Skip to content
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

Consider resolving root __typename as schema introspection #867

Open
yanns opened this issue Jun 12, 2024 · 3 comments
Open

Consider resolving root __typename as schema introspection #867

yanns opened this issue Jun 12, 2024 · 3 comments
Labels
apollo-compiler issues/PRs pertaining to semantic analysis & validation introspection triage

Comments

@yanns
Copy link
Contributor

yanns commented Jun 12, 2024

Description

SchemaIntrospectionQuery::split_and_execute cannot solve the query { __typename }

Steps to reproduce

I'm playing with the introspection with a code similiar to https://github.com/apollographql/apollo-rs/pull/859/files

When I use a query like { __schema { types { name } } }, everything is working fine.
When I use the query { __typename }, the execute_non_introspection_parts function is being called.

Expected result

SchemaIntrospectionQuery::split_and_execute should solve the query { __typename } and return the following:

{
  "data": {
    "__typename": "Query"
  }
}

Actual result

The code panic as the following function is being called:

|_| panic!("Provided query must not have non-introspection elements")

https://github.com/apollographql/apollo-rs/pull/859/files#diff-6416f1ff6c1a61aa6817f3430bcde09ca29f1fdb819603a5058d7991a33adfd1R42

Environment

  • apollo-compiler = "=1.0.0-beta.17"
@yanns yanns added bug Something isn't working triage labels Jun 12, 2024
@SimonSapin
Copy link
Contributor

This intentional, but we can consider changing it.

Type name introspection is separate from Schema introspection in the spec, and the name SchemaIntrospectionQuery was picked to reflect that. In the general case, resolving __typename nested inside of a field may requires “actual” execution if that field has an interface or union type.

Specifically at the root of an operation however, because all root operation types must be object types (not interface or union), __typename could be correctly resolved based on only the schema. And since bare { __typename } is a semi-common “is this URL a running GraphQL server” query it may be worth bending the definition a bit and resolving it like schema introspection without involving “normal” execution machinery.

@SimonSapin SimonSapin added apollo-compiler issues/PRs pertaining to semantic analysis & validation introspection and removed bug Something isn't working labels Jun 13, 2024
@SimonSapin SimonSapin changed the title Introspection query cannot be resolved with SchemaIntrospectionQuery::split_and_execute Consider resolving root __typename as schema introspection Jun 13, 2024
@yanns
Copy link
Contributor Author

yanns commented Jun 13, 2024

Thanks for the explanation, it makes perfect sense.

And I guess that Operation::is_introspection returns true for all kinds of introspection, schema and type name?
I'm using this information to know if it's an introspection query, and in that case I'm using SchemaIntrospectionQuery . But this will not work for type name introspection.
Do you think we should introduce more fine grained Operation::is_introspection?

@SimonSapin
Copy link
Contributor

The concept of a is_introspection method that returns a boolean is wrong since you can query __schema and "normal" fields in the same operation. I’d like to remove it after Router fully moves to the Rust implementation of introspection. Its replacement is SchemaIntrospectionSplit::split

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
apollo-compiler issues/PRs pertaining to semantic analysis & validation introspection triage
Projects
None yet
Development

No branches or pull requests

2 participants