-
Notifications
You must be signed in to change notification settings - Fork 48
client_introspection
- Use GraphQL introspection with the GraphQL client mode
- Introspection queries
- __typename in GraphQL types
- How the code is generated
On server side, the introspection is directly managed by graphql-java. There is no additional work to do, to make it work.
On client side, graphql-java-generator makes it easy to execute GraphQL introspection queries. And the query's response is stored in java classes that match the GraphQL introspection schema.
As specified in the GraphQL specification, there are two main queries: __schema and __type.
You can access to the introspection GraphQL capabilities through the _IntrospectionQuery class. This class is generated in the same package as the other classes (see the client exec GraphQL requests page for details).
You can then execute introspection queries like this:
// your.target.package is the package defined in the pom or build.gradle file, as the 'packageName'
import your.target.package.QueryExecutor;
import your.target.package.__Schema;
import your.target.package.__Type;
@Component
public class MyClass {
@Autowired
QueryExecutor executor;
public __Schema getSchema() {
return executor.__schema("{types {name fields {name type {name}}}}");
}
public __Type getType() {
return executor.__type("{name fields {name type {name}}}", "MyGraphQLType");
}
}
In the generated code, a field named __typename is added into each java class that is actually a GraphQL type. So you can ask for the GraphQL type name of a response with a query request like this one:
AllFieldCases allFieldCases = queryExecutor.allFieldCases("{id __typename {friends __typename}}", null);
When the plugin is in client mode, the introspection capabilities are added to the Query type defined in the GraphQL schema you've provided. And the __Schema and __Type are added to your GraphQL schema content. So these types are generated in the same package as the other classes.
Creating a first app (non spring)
Connect to more than one GraphQL servers
Easily execute GraphQL requests with GraphQL Repositories
Access to an OAuth2 GraphQL server
How to personalize the client app
Howto personalize the generated code
Client migration from 1.x to 2.x
Implement an OAuth2 GraphQL server
Howto personalize the generated code
Server migration from 1.x to 2.x