profusion / sgqlc

Simple GraphQL Client
https://sgqlc.readthedocs.io/
ISC License
513 stars 85 forks source link

Issues with operation generator #215

Closed TheZwieback closed 1 year ago

TheZwieback commented 2 years ago

Hi, I am using the generator to create an operations.py file from multiple input files and deep import path. My generate command is:

sgqlc-codegen operation --schema schema.json src.services.apc.graphql.schema operations.py graphql/orders.gql graphql/hierarchy.gql

The generated operations.py file has two issues: The schema import path is:

_schema = src.services.apc.graphql.schema
_schema_root = _schema.src.services.apc.graphql.schema

but should be

_schema = src.services.apc.graphql.schema
_schema_root = _schema.schema

And the other issue is the generated operations.py file contains multiple definitions of Operations, Mutation and Query class, one for each file, but only one of each with all queries/mutations should exist.

The full generated file (except execution methods):

import sgqlc.types
import sgqlc.operation
import src.services.apc.graphql.schema

_schema = src.services.apc.graphql.schema
_schema_root = _schema.src.services.apc.graphql.schema

__all__ = ('Operations',)

...

class Mutation:
    create_forecast_orders = mutation_create_forecast_orders()
    delete_forecast_orders = mutation_delete_forecast_orders()

...

class Query:
    get_forecasts_in_horizon = query_get_forecasts_in_horizon()
    get_locations_by_name = query_get_locations_by_name()
    get_products_by_name = query_get_products_by_name()

class Operations:
    mutation = Mutation
    query = Query

...

class Mutation:
    get_location_product_location_hierarchy = mutation_get_location_product_location_hierarchy()
    get_location_product_product_hierarchy = mutation_get_location_product_product_hierarchy()

class Operations:
    mutation = Mutation
marcown commented 1 year ago

I have the same issue, did you fix it somehow?

marcown commented 1 year ago

nvm: I just merged them beforehand in my script:

cat ./gql/**/*.graphql > ./merged.graphql
barbieri commented 1 year ago

closing this issue, since can be solved by concatenating the documents before processing.