Created
April 5, 2020 19:29
-
-
Save ilyaskarim/9745279ee77b0e016cf837c47b2e2c80 to your computer and use it in GitHub Desktop.
Wertik-js custom module - GraphQL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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