profusion / sgqlc

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

Supporting a few schemas #240

Closed ALeksandr-Fuze closed 1 year ago

ALeksandr-Fuze commented 1 year ago

Needs help with how to support a different query types.

As an example I have 2 different queries that have different structure:

company

class Query(Type):
    companies = Field(AvailableCompanies, graphql_name="availableCompanies")

company_items

class Query(Type):
    use_company = Field(UseCompany, graphql_name="useCompany", args=ArgDict(no=int))

main

from company_items import Query as CompanyItemsQuery
from company import Query as CompanyQuery

class GraphQueries:
     def company_query(self):
        operation = Operation(ItemQuery)
        ...  
     def company_items_query(self):
        operation = Operation(CompanyItemsQuery)
        ...

But running the main file I get:

sgqlc\types\__init__.py", line 830, in __iadd__
    raise ValueError(
ValueError: Schema already has Query=Query
ALeksandr-Fuze commented 1 year ago

I found a solution. Needs to create a combined Query object inside the main module like:

main

class Query(Type):
    companies = Field(AvailableCompanies, graphql_name="availableCompanies")
    use_company = Field(UseCompany, graphql_name="useCompany", args=ArgDict(no=int))

class GraphQueries:
     def company_query(self):
        operation = Operation(Query)
        ...  
     def company_items_query(self):
        operation = Operation(Query)
        ...