Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api platform #55

Draft
wants to merge 11 commits into
base: api
Choose a base branch
from
Draft

api platform #55

wants to merge 11 commits into from

Conversation

chihiro-adachi
Copy link
Contributor

@chihiro-adachi chihiro-adachi commented Jul 4, 2023

$ composer req api

In ApiPlatformExtension.php line 447:
                                                                                       
  Could not open file or directory "/Users/chihiro_adachi/repos/next-poc/src/Entity".  

$ vi app/config/eccube/packages/api_platform.yaml

api_platform:
    mapping:
        # todo src/framework/Eccube/Entityは自動で検出されてるぽいけど一応追加
        # todo プラグインのEntityはExtensionかCompilerPassで対応
        paths:
            - '%kernel.project_dir%/src/framework/Eccube/Entity'
            - '%kernel.project_dir%/src/application/Eccube/Entity'
            - '%kernel.project_dir%/app/Customize/Entity'    patch_formats:
        json: ['application/merge-patch+json']
    swagger:
        versions: [3]

$ bin/console debug:config api_platform

Current configuration for extension with alias "api_platform"
=============================================================

Current configuration for extension with alias "api_platform"
=============================================================

api_platform:
    mapping:
        paths:
            - /Users/chihiro_adachi/repos/next-poc/src/framework/Eccube/Entity
            - /Users/chihiro_adachi/repos/next-poc/src/application/Eccube/Entity
            - /Users/chihiro_adachi/repos/next-poc/app/Customize/Entity

$ mkdir -p html/template/default/bundles/
$ cp -r vendor/api-platform/core/src/Symfony/Bundle/Resources/public html/template/default/bundles/apiplatform

$ symfony server:start
$ open https://127.0.0.1:8000/api

image

@codecov-commenter
Copy link

codecov-commenter commented Jul 4, 2023

Codecov Report

Merging #55 (1af2b71) into api (c017ec3) will decrease coverage by 2.95%.
The diff coverage is 0.00%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

@@             Coverage Diff              @@
##                api      #55      +/-   ##
============================================
- Coverage     79.50%   76.55%   -2.95%     
- Complexity     7265     7272       +7     
============================================
  Files           604      612       +8     
  Lines         28255    28276      +21     
============================================
- Hits          22464    21648     -816     
- Misses         5791     6628     +837     
Flag Coverage Δ
E2E 2.51% <0.00%> (-66.46%) ⬇️
Unit 77.04% <0.00%> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/application/Eccube/Entity/BaseInfo.php 82.08% <ø> (-6.94%) ⬇️
src/application/Eccube/Entity/CartItem.php 83.33% <ø> (ø)
src/application/Eccube/Entity/Customer.php 89.50% <ø> (-1.00%) ⬇️
src/application/Eccube/Entity/Member.php 85.71% <ø> (ø)
src/application/Eccube/Entity/Order.php 91.28% <ø> (-1.09%) ⬇️
src/application/Eccube/Entity/OrderItem.php 94.24% <ø> (ø)
src/application/Eccube/Entity/ProductClass.php 92.70% <ø> (ø)
src/application/Eccube/Entity/Shipping.php 84.00% <ø> (ø)
...application/Eccube/Repository/SampleRepository.php 0.00% <0.00%> (ø)
...amework/Eccube/Api/Extension/AbstractExtension.php 0.00% <0.00%> (ø)
... and 5 more

... and 71 files with indirect coverage changes

@nanasess
Copy link
Contributor

nanasess commented Jul 4, 2023

既存の Entity に #[ApiResource] をつければ Swagger の画面から API コールできるようになりますが、実際に API コールすると以下の例外になるので、ちょっと障壁がありそう😢

ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\FilterExtension::applyToCollection(): Argument #1 ($queryBuilder) must be of type Doctrine\ORM\QueryBuilder, Eccube\ORM\QueryBuilder given, called in /var/www/html/vendor/api-platform/core/src/Core/Bridge/Doctrine/Orm/CollectionDataProvider.php on line 73

@chihiro-adachi
Copy link
Contributor Author

Customerに#[ApiResource]つけると Class "Eccube\Entity\boolean" does not exist の謎エラー
image

@chihiro-adachi
Copy link
Contributor Author

FavariteProducts, CustomerAddresses, Orders 関連のメソッドをコメントアウトすると通る
0925ef7

@chihiro-adachi
Copy link
Contributor Author

@nanasess
これでどうでしょう
f5def87

@chihiro-adachi
Copy link
Contributor Author

chihiro-adachi commented Jul 4, 2023

"ApiPlatform\\Core\\Bridge\\Doctrine\\Orm\\ItemDataProvider::addWhereForIdentifiers(): Argument #2 ($queryBuilder) must be of type Doctrine\\ORM\\QueryBuilder, Eccube\\ORM\\QueryBuilder given, called in /Users/chihiro_adachi/repos/next-poc/vendor/api-platform/core/src/Core/Bridge/Doctrine/Orm/ItemDataProvider.php on line 107

ItemDataProvider:: addWhereForIdentifiersはprivateなので独自実装必要かも
https://zenn.dev/ttskch/books/a3800fc0912fbb/viewer/4

@chihiro-adachi
Copy link
Contributor Author

Class "Eccube\Entity\boolean" does not exist241228c で解消

@chihiro-adachi
Copy link
Contributor Author

$ composer require webonyx/graphql-php

https://127.0.0.1:8000/api/graphql
https://127.0.0.1:8000/api/graphql/graphql_playground

@chihiro-adachi
Copy link
Contributor Author

…t ApiPlatform\Core\DataProvider\PaginatorInterface or ApiPlatform\Core\DataProvider\PartialPaginatorInterface.
@chihiro-adachi
Copy link
Contributor Author

Collection returned by the collection data provider must implement ApiPlatform\\Core\\DataProvider\\PaginatorInterface or ApiPlatform\\Core\\DataProvider\\PartialPaginatorInterface.

を回避

d731c79

@nanasess
Copy link
Contributor

nanasess commented Jul 6, 2023

mutation は以下のような感じで動作するのを確認

mutation {
  createCustomer(input: {
    name01: ""
    name02: "九部"
    email: "[email protected]"
    password: "password"
    point: "0"
    secretKey: "key"
    createDate: "2023-07-06T00:00:00Z"
    updateDate: "2023-07-06T00:00:00Z"
    propertiesFromArray: []
  }) {
    customer {
      id
      name01
      name02
      email
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants