Skip to content

Instantly share code, notes, and snippets.

@ilyaskarim
Created April 5, 2020 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ilyaskarim/9745279ee77b0e016cf837c47b2e2c80 to your computer and use it in GitHub Desktop.
Save ilyaskarim/9745279ee77b0e016cf837c47b2e2c80 to your computer and use it in GitHub Desktop.
Wertik-js custom module - GraphQL
let configuration = {
modules: [
{
// other module configuration
graphql: {
crud: {
query: {
generate: true,
operations: "*", // Options are view, list
},
mutation: {
generate: true,
operations: "*", // Options are create update delete softDelete bulkcreate bulkupdate bulkdelete bulkSoftDelete
},
},
// In schema you have to Provide same type as you provided the moduleName, Consider you have provided Person you have to set it as Person with attributes
// PersonInput is an input that will be used for mutations. If you set your module to Person then input name should be PersonInput
schema: `
type Person {
id: Int
name: String
}
input PersonInput {
id: Int
name: String
}
`,
// You can add more custom mutations to this module, See below
mutation: {
schema: `
UpdatePersonWithUser(input: PersonInput): Person
`,
resolvers: {
// Here as you have set mutation name as UpdatePersonWithUser, you have provide a method with same name:
UpdatePersonWithUser: async (_, args, context, info) => {
// _ is the fields parent, as Apollo states: The return value of the resolver for this field's parent (i.e., the previous resolver in the resolver chain).
// args is the object passed from oustide
// For please see context part
// info is the information about Query
// Read more about resolver arguments here: https://www.apollographql.com/docs/apollo-server/data/resolvers/#resolver-arguments
return {} // Something
}
},
},
query: {
// You can add custom Query to your module
schema: `
ReturnbasicPerson: Person
`,
resolvers: {
ReturnbasicPerson: async (_, args, context, info) => {
return {
id: 1,
name: "John"
}
}
},
},
},
},
],
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment