datamodel-code-generator icon indicating copy to clipboard operation
datamodel-code-generator copied to clipboard

Generation of Shopify GraphQL schema fails

Open mairas opened this issue 1 year ago • 0 comments

Describe the bug

I have downloaded the latest GraphQL schema of our Shopify store with the following commands:

npm install -g get-graphql-schema
get-graphql-schema -h 'X-Shopify-Access-Token=REDACTED' https://hat-labs.myshopify.com/admin/api/2024-04/graphql.json > shopify_schema_2024-04.graphql

The downloaded schema is attached below.

I am attempting to use the following command to generate data models for it:

datamodel-codegen --output shopify_gql_schema.py --input shopify_schema_2024-04.graphql --input-file-type graphql --target-python-version 3.11

This results in the following stack trace and error:

Traceback (most recent call last):
  File "/opt/homebrew/Caskroom/mambaforge/base/lib/python3.12/site-packages/datamodel_code_generator/__main__.py", line 428, in main
    generate(
  File "/opt/homebrew/Caskroom/mambaforge/base/lib/python3.12/site-packages/datamodel_code_generator/__init__.py", line 462, in generate
    results = parser.parse()
              ^^^^^^^^^^^^^^
  File "/opt/homebrew/Caskroom/mambaforge/base/lib/python3.12/site-packages/datamodel_code_generator/parser/base.py", line 1289, in parse
    body = code_formatter.format_code(body)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Caskroom/mambaforge/base/lib/python3.12/site-packages/datamodel_code_generator/format.py", line 226, in format_code
    code = self.apply_black(code)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Caskroom/mambaforge/base/lib/python3.12/site-packages/datamodel_code_generator/format.py", line 234, in apply_black
    return black.format_str(
           ^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Caskroom/mambaforge/base/lib/python3.12/site-packages/black/__init__.py", line 1232, in format_str
    dst_contents = _format_str_once(src_contents, mode=mode, lines=lines)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Caskroom/mambaforge/base/lib/python3.12/site-packages/black/__init__.py", line 1246, in _format_str_once
    src_node = lib2to3_parse(src_contents.lstrip(), mode.target_versions)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Caskroom/mambaforge/base/lib/python3.12/site-packages/black/parsing.py", line 90, in lib2to3_parse
    raise exc from None
black.parsing.InvalidInput: Cannot parse: 28209:4: The concrete type can be `AppRecurringPricing` for recurring billing or `AppUsagePricing` for usage-based billing.

To Reproduce

Example schema:

Renamed to .txt to allow uploading: shopify_schema_2024-04.txt

Used commandline:

$ datamodel-codegen --output shopify_gql_schema.py --input shopify_schema_2024-04.graphql --input-file-type graphql --target-python-version 3.11

Expected behavior

I assumed I'd get a Pydantic schema definition in the output file. This is my first time trying to use datamode-codegen, so my expectations were quite vague. :-)

Version:

  • OS: MacOS Sonoma 14.2.1
  • Python version: 3.12.2 (Installed using Conda)
  • datamodel-code-generator version: 0.25.5

mairas avatar Apr 09 '24 08:04 mairas