CRUD Overview
Graphback generates a CRUD API for each model in your GraphQL schema. This gives you queries, mutations and subscriptions that can be instantly be used perform queries and mutations on your data.
Graphback provides an implementation of GraphQLCRUD for a standardised CRUD API using common data access patterns.
Queries, mutations and subscriptions that you add to your model files will be included in the generated schema. These require manual implementation and merging with the resolvers generated by Graphback.
Your custom operations can utilize the input types and filters created by Graphback. This lets you control the schema as you would when building it from scratch, while significantly reducing the amount of boilerplate required to set up it from your data.
To tell Graphback to create a CRUD API for your type, add a @model
annotation.
This will add queries, mutations and subscriptions to the schema for Note
. It will also create corresponding CRUD resolvers which are configured to access the data from your data source.
caution
Graphback will override custom queries, mutations and subscriptions from model files which have the same name as Graphback CRUD queries, mutations and subscriptions. Either change the name of your custom definitions or disable generation of the CRUD operation(s) for the model(s).
#
ConfigurationGraphback can be configured to enable/disable CRUD generation per GraphQL type, or globally across the entire application.
See the table below for the full list of CRUD configuration options that can be applied to the application or models.
Option | Description | Default |
---|---|---|
find | Specifies whether a find<Type>s findBy query should be generated. | true |
findOne | Specifies whether a get<Type> findOne query should be generated. | true |
create | Specifies whether a create<Type> query should be generated. | true |
update | Specifies whether a update<Type> update mutation should be generated. | true |
delete | Specifies whether a delete<Type> delete mutation should be generated. | true |
subCreate | Specifies whether a new<Type> subscription should be generated. | true |
subUpdate | Specifies whether a updated<Type> subscription should be generated. | true |
subDelete | Specifies whether a deleted<Type> subscription should be generated. | true |
#
Application wideYou can configure different CRUD methods to be enabled or disabled across all data models in buildGraphbackAPI
through the crud
config option.
In this example, generation of the delete
mutation for all models is disabled.
caution
CRUD configuration set on an individual type with the @model
annotation will override the application-wide CRUD configuration.
#
Per typeCRUD can be enabled/disabled individually for each model in your schema with the @model
annotation.
This disables deleteNote
generation for Note
.
caution
CRUD configuration set with @model
will override the application-wide CRUD configuration value for that type only.