Skip to content

DSL does not support custom root operation names #307

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

Closed
motybz opened this issue Mar 17, 2022 · 6 comments
Closed

DSL does not support custom root operation names #307

motybz opened this issue Mar 17, 2022 · 6 comments
Labels
type: bug An issue or pull request relating to a bug

Comments

@motybz
Copy link

motybz commented Mar 17, 2022

I'm trying to create a DSL query but I got the following error on the query compilation:

GraphQLError: Invalid field for <DSLQuery>: <DSLField QueryGTEMMetadata::clipsMetadata>

The instance init:

class MyClient():
    SCHEMA_FILE_NAME = "gtem_schema.graphql"
    
    @classmethod
    def _get_my_gql_scheme(cls) -> str:
        location = f"{os.path.dirname(os.path.abspath(__file__))}/gql/{cls.SCHEMA_FILE_NAME}"
        schema_str = open(location).read()
        return schema_str

    def __init__(self, env: str = "production") -> None:
        super().__init__(env)
        self.s3fs = boto3.client('s3')
        transport = RequestsHTTPTransport(url=f'{self.config["graphql_api"]["host"]}', verify=True, retries=3)
        self.gql_client = Client(schema=self._get_my_gql_scheme(), transport=transport)
        **self.gql_dsl_schema = DSLSchema(self.gql_client.schema)**

The DSLQuery compilation issue

main_query = self.gql_dsl_schema.QueryGTEMMetadata.clipsMetadata
select_query = main_query .select(self.gql_dsl_schema.GTEMMetadataWithArtifactsGQL.gtemVersion)
query = dsl_gql(DSLQuery(select_query)) # <- it's failed herer
result = self.gql_client.execute(query)

The gtem_schema.graphql content

schema {
  query: QueryGTEMMetadata
}

type QueryGTEMMetadata {
  """Gets gtem metadata by clip list"""
  clipsMetadata(clipList: [String!]!, version: String = null): [GTEMMetadataWithArtifactsGQL!]!
}

type GTEMMetadataWithArtifactsGQL {
  usedCameras: [String!]!
  coordinateCamera: String!
  cameraConfHash: String!
  sessionName: String!
  gtemVersion: String!
  packageVersion: String!
  dataPath: String!
  artifacts: [GTEMArtifactGQL!]
}

type GTEMArtifactGQL {
  filePath: String!
  clipNames: [String!]!
  startFrameId: Int!
  endFrameId: Int!
  startGrabIndex: Int!
  endGrabIndex: Int!
  id: String
  startUtcMicro: Int
  endUtcMicro: Int
}

Full logs and traceback:

DEBUG:gql.dsl:Creating <DSLType <GraphQLObjectType 'QueryGTEMMetadata'>>)
DEBUG:gql.dsl:Creating <DSLField QueryGTEMMeta[data::clipsMetadata>]()
DEBUG:gql.dsl:Added arguments {'clipList': ['name5'], 'version': None} in field <DSLField QueryGTEMMeta[data::clipsMetadata>]())
DEBUG:gql.dsl:Creating <DSLType <GraphQLObjectType 'GTEMMetadataWithArtifactsGQL'>>)
DEBUG:gql.dsl:Creating <DSLField GTEMMetadataWithArtifactsGQL::gtemVersion>
DEBUG:gql.dsl:Added fields: (<DSLField GTEMMetadataWithArtifactsGQL::gtemVersion>,) in <DSLField QueryGTEMMeta[data::clipsMetadata>]()
---------------------------------------------------------------------------
GraphQLError                              Traceback (most recent call last)
/workspace/client/doogle/gtem.py in _get_metadata_list(self, returned_fields, clip_names, version)
    111         clips_query = self.gql_dsl_schema.QueryGTEMMetadata.clipsMetadata
    112         select_query = clips_query.select(self.gql_dsl_schema.GTEMMetadataWithArtifactsGQL.gtemVersion)
--> 113         query = dsl_gql(DSLQuery(select_query))
    114                             # self.gql_dsl_schema.GTEMMetadataWithArtifactsGQL.artifacts.select(self.gql_dsl_schema.GTEMArtifactGQL.clipNames)
    115         result = self.gql_client.execute(query)

/opt/conda/envs/doogle_client/lib/python3.7/site-packages/gql/dsl.py in __init__(self, *fields, **fields_with_alias)
    412         self.variable_definitions = DSLVariableDefinitions()
    413 
--> 414         DSLSelector.__init__(self, *fields, **fields_with_alias)
    415 
    416 

/opt/conda/envs/doogle_client/lib/python3.7/site-packages/gql/dsl.py in __init__(self, *fields, **fields_with_alias)
    318 
    319         if fields or fields_with_alias:
--> 320             self.select(*fields, **fields_with_alias)
    321 
    322     @abstractmethod

/opt/conda/envs/doogle_client/lib/python3.7/site-packages/gql/dsl.py in select(self, *fields, **fields_with_alias)
    353 
    354             if not self.is_valid_field(field):
--> 355                 raise GraphQLError(f"Invalid field for {self!r}: {field!r}")
    356 
    357         # Get a list of AST Nodes for each added field

GraphQLError: Invalid field for <DSLQuery>: <DSLField QueryGTEMMetadata::clipsMetadata>

System info (please complete the following information):

  • OS: Linux
  • Python version: Python 3.7.12
  • gql version: Version: 3.1.0
  • graphql-core version: Version: 3.2.0
@leszekhanusz
Copy link
Collaborator

It seems to be a bug.
Apparently we assume incorrectly that the root operation type names are the default names: Query, Mutation, Subscription (relevant GraphQL spec)

It you can modify your schema, then it should work if you rename QueryGTEMMetadata to Query

@leszekhanusz leszekhanusz added the type: bug An issue or pull request relating to a bug label Mar 17, 2022
@fgutierrezRPage
Copy link

fgutierrezRPage commented Mar 18, 2022

Just wanted to add feedback here. I was having the same issue where mine was setup with query : query_root and changed it to query: Query and renamed the type to Query. Luckly I was able to download the schema and modify it per @leszekhanusz suggestion and it works. I do need to keep track of this bug because we update our GraphQL Server frequently and I would like to be able to use this with introspection and schema auto fetching.

@motybz
Copy link
Author

motybz commented Mar 20, 2022

Thank you @leszekhanusz and @fgutierrezRPage
I'm also the server developer so it was easy to make the workaround.
Thank you!

@leszekhanusz leszekhanusz changed the title GraphQLError: Invalid field for <DSLQuery>: <DSLField> when using DSL DSL does not support custom root operation names Apr 11, 2022
@leszekhanusz
Copy link
Collaborator

It should be fixed in #320

@leszekhanusz
Copy link
Collaborator

Released in version 3.2.0

@fgutierrezRPage
Copy link

@leszekhanusz Thanks so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug An issue or pull request relating to a bug
Projects
None yet
Development

No branches or pull requests

3 participants