We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
The following is a collection of commons scenarios, with the goal of providing step-by-step explanations of how to go about them.
All scenarios are based on typescript-basic.
typescript-basic
Adding a new address field to the user type in the database, with the purpose of exposing it in the application API as well.
in database/datamodel.graphql:
database/datamodel.graphql
type User { id: ID! @unique email: String! @unique password: String! name: String! posts: [Post!]! @relation(name: "UserPosts") + address: String }
graphcool deploy
This will
database/schema.graphql
in src/schema.graphql:
src/schema.graphql
type User { id: ID! email: String! name: String! posts: [Post!]! + address: String }
Suppose we want to add a custom resolver to delete a post.
Add a new delete field to the Mutation type in src/schema.graphql
delete
type Mutation { createDraft(title: String!, text: String): Post publish(id: ID!): Post + delete(id: ID!): Post }
Add a delete resolver to Mutation part of src/index.js
src/index.js
delete(parent, { id }, ctx, info) { return ctx.db.mutation.deletePost( { where: { id } }, info ); }
Run yarn start.
yarn start
Then we can run the following mutation to delete a post:
mutation { delete(id: "post-id") { id } }
The text was updated successfully, but these errors were encountered:
removed instructions about adding new resolver
7d18dde
collecting them in #35 instead
f948a33
collecting them in graphql-boilerplates/node-graphql-server#35 instead
515a603
nikolasburk
No branches or pull requests
Scenarios
The following is a collection of commons scenarios, with the goal of providing step-by-step explanations of how to go about them.
All scenarios are based on
typescript-basic
.Adding fields to an existing type
Example & Instructions
Example
Adding a new address field to the user type in the database, with the purpose of exposing it in the application API as well.
Instructions
1. Adding the field to the data model
in
database/datamodel.graphql
:type User { id: ID! @unique email: String! @unique password: String! name: String! posts: [Post!]! @relation(name: "UserPosts") + address: String }
2. Deploying the updated data model
This will
database/schema.graphql
3. Adding the field to the application schema
in
src/schema.graphql
:type User { id: ID! email: String! name: String! posts: [Post!]! + address: String }
Adding a new resolver to the GraphQL server
Example & Instructions
Example
Suppose we want to add a custom resolver to delete a post.
Instructions
Add a new
delete
field to the Mutation type insrc/schema.graphql
type Mutation { createDraft(title: String!, text: String): Post publish(id: ID!): Post + delete(id: ID!): Post }
Add a
delete
resolver to Mutation part ofsrc/index.js
Run
yarn start
.Then we can run the following mutation to delete a post:
Further resolver-centric scenarios
Other scenarios
The text was updated successfully, but these errors were encountered: