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

Introduce a generic GraphQL base resolver #252

Merged
merged 7 commits into from
Jan 29, 2021

Conversation

dnlkoch
Copy link
Member

@dnlkoch dnlkoch commented Jan 29, 2021

Backport of #221 to the main.

This introduces a BaseGraphQLDataFetcher which registers several base GraphQL queries and mutations (!) once implemented for a given entity (e.g. ApplicationGraphQLDataFetcher). The names of the queries will be autogenerated for each available operation following simple conventions:

  • findAll
    • all{BaseEntities}, e.g. allApplications
  • findOne
    • {BaseEntity}ById, e.g. applicationById
  • create
    • create{BaseEntity}, e.g. createApplication
  • update
    • update{BaseEntity}, e.g. updateApplication
  • delete
    • delete{BaseEntity}, e.g. deleteApplication

Please see the shogun.graphqls for a full list of available queries and mutations.

Upgrade notes for projects:

  • The property shogun.graphql.skipBean is no longer needed and can be removed from the application.yml
  • Any custom GraphQLProvider can be removed.
  • Any custom data fetcher (registered in the GraphQLProvider) should be moved to a single resolver, e.g.:
@Component
public class MyEntityGraphQLDataFetcher extends BaseGraphQLDataFetcher<MyEntity, MyEntityService> {

    @Autowired
    private MyEntityRepository repository;

    @GraphQLQuery(name = "myEntityBySomething")
    public DataFetcher myEntityBySomething() {
        return dataFetchingEnvironment -> {
            String something = dataFetchingEnvironment.getArgument("something");
            return this.repository.findBySomething(something);
        };
    }
}

(Note the annotation @GraphQLQuery which defines the name of the query which is needed to register it in the schema file.)

Please review @terrestris/devs.

(In addition a new service method for returning the owner an entity has been added.)

@dnlkoch dnlkoch force-pushed the generic-graphql-base-fetcher-main branch from d56283c to dd4bb00 Compare January 29, 2021 17:02
@dnlkoch dnlkoch merged commit 95d9d5e into master Jan 29, 2021
@dnlkoch dnlkoch deleted the generic-graphql-base-fetcher-main branch January 29, 2021 17:08
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

Successfully merging this pull request may close these issues.

1 participant