-
Notifications
You must be signed in to change notification settings - Fork 184
Validation error using '@include' directive if schema comes from introspection #278
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
Comments
Hi, Which versions of gql and graphql-core are you using ? |
Hi @leszekhanusz , I've just updated my OP. |
How did you provide your schema? By using introspection or by providing your own schema.graphql file? |
I set "fetch_schema_from_transport" in client to True. I found out that when I switch "fetch_schema_from_transport" to False, the query can work now. This my full test code if you interest import gql
from gql.transport.requests import RequestsHTTPTransport
query = """
query fetchPool($with_swap: Boolean!) {
pool(id: "0x83abecf7204d5afc1bea5df734f085f2535a9976") {
id
createdAtTimestamp
swaps (first: 2) @include(if: $with_swap ) {
id
timestamp
}
}
}
"""
UNISWAP_V3_ENDPOINT = 'https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v3'
transport = RequestsHTTPTransport(
url=UNISWAP_V3_ENDPOINT, verify=True, retries=3,
)
client = gql.Client(transport=transport, fetch_schema_from_transport=True)
q = gql.gql(query)
result = client.execute(q, variable_values= {'with_swap': True})
print(result) |
I tried to valide your query using a provided
This was solved by adding the required subgraphError field: import gql
from gql.transport.requests import RequestsHTTPTransport
query = """
query fetchPool($with_swap: Boolean!) {
pool(id: "0x83abecf7204d5afc1bea5df734f085f2535a9976", subgraphError: allow) {
id
createdAtTimestamp
swaps (first: 2) @include(if: $with_swap ) {
id
timestamp
}
}
}
"""
UNISWAP_V3_ENDPOINT = 'https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v3'
with open("./schema.graphql") as f:
schema_str = f.read()
transport = RequestsHTTPTransport(
url=UNISWAP_V3_ENDPOINT, verify=True, retries=3,
)
client = gql.Client(transport=transport, schema=schema_str)
q = gql.gql(query)
result = client.execute(q, variable_values= {'with_swap': True})
print(result) This is probably a bug in graphql-core. It is not normal that the include directive is not supported if the schema is fetched from the backend using introspection. |
Thanks for your report! |
@Cito could you please take a look at this bug? |
@Cito I have received your message in a notification email but it does not appear here. GitHub having some issues perhaps? Anyway to answer your question: In # If specified directives were not explicitly declared, add them.
if not any(directive.name == "skip" for directive in directives):
directives.append(GraphQLSkipDirective)
if not any(directive.name == "include" for directive in directives):
directives.append(GraphQLIncludeDirective)
if not any(directive.name == "deprecated" for directive in directives):
directives.append(GraphQLDeprecatedDirective)
if not any(directive.name == "specifiedBy" for directive in directives):
directives.append(GraphQLSpecifiedByDirective) There is nothing corresponding in the |
Hi @leszekhanusz - yes, I understood the problem after reading again and therefore deleted my comment. As you already noticed, the problem is the different behavior of
Or, you could somehow fumble the missing default directives into |
Fixed in version 3.0.0rc0 |
When I try to use "@include" directive in my string query, I got this error:
graphql.error.graphql_error.GraphQLError: Unknown directive '@include'.
I think "@include" and "@Skip" are in standards of GraphQL https://graphql.org/learn/queries/#directives
Version in my environment
GraphQL Query
Full stack trace:
The text was updated successfully, but these errors were encountered: