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

create an hook to add: TypeResolver and Datafetcher #279

Open
heiko-he opened this issue Jul 6, 2020 · 0 comments
Open

create an hook to add: TypeResolver and Datafetcher #279

heiko-he opened this issue Jul 6, 2020 · 0 comments

Comments

@heiko-he
Copy link

heiko-he commented Jul 6, 2020

When the GraphQL schema was build and not yet used in the GraphQL-server then needs an hook to modify/transform the GraphQL schema. The new schema should be used after the calling of the hook.

TypeResolver and Datafetcher are mandatory in federated GraphQL schemas. They can be add by the transformation process from single to federational schema.

This tools for transformation and usage gets by the following library:
com.apollographql.federation
federation-graphql-java-support
0.4.0

This snippet transformed the given single GraphQL schema to a federational GraphQL schema:

import com.apollographql.federation.graphqljava.Federation;
import com.apollographql.federation.graphqljava.SchemaTransformer;
import graphql.schema.GraphQLSchema;

public class SchemaService {
GraphQLSchema transformToFederationalSchema(GraphQLSchema originalSchema) {
SchemaTransformer schemaTransformer = Federation.transform(originalSchema);
schemaTransformer.resolveEntityType(() ->{
.......;
});
schemaTransformer.fetchEntities(()->{
......
});
GraphQLSchema federationalSchema = schemaTransformer.build();
return federationalSchema;
}
}

Some more informations here (with spring):
https://github.com/apollographql/federation-jvm
https://github.com/rkudryashov/graphql-java-federation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant