Skip to content

Instantly share code, notes, and snippets.

@ilyaskarim
Last active April 5, 2020 15:45
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/dd2248dbe30d797c216e4147c1cb60ff to your computer and use it in GitHub Desktop.
Save ilyaskarim/dd2248dbe30d797c216e4147c1cb60ff to your computer and use it in GitHub Desktop.
wertik-js-configuration-custom-module
let otherConfiguration = {}; // Here other wertik configuration
let configuration = {
...otherConfiguration,
modules: [
{
name: "Article",
useDatabase: true,
fields: {
sql: {
title: {
type: "String",
},
},
},
graphql: {
crud: {
query: {
generate: true,
operations: "*",
},
mutation: {
generate: true,
operations: "*",
},
},
// Main schema for Article
schema: `
type Article {
title: String
}
type ArticleInput {
title: String
}
`,
mutation: {
schema: ``, // Write mutation schema for your module Article
resolvers: {}, // Resolvers for article mutations
},
query: {
schema: ``, // Write query schema for your module Article
resolvers: {}, // Resolvers for article query
},
},
restApi: {
endpoints: [
{
path: "/people/", // Will be available under http://localhost:port/api/v1/article/people/
methodType: "get", // get,post,put,delete,copy,head,options,link,unlink,purge,lock,unlock,view
handler: async function (req, res, restApiSuccessResponse, restApiErrorResponse) {
let somethinWentFine = true;
if (somethinWentFine) {
restApiSuccessResponse({
res: res,
data: {
success: true,
},
message: `Went all fine`,
});
} else {
restApiErrorResponse({
err: Error,
res: res,
data: {
message: "Something went wrong",
message: "Detail",
},
});
}
},
},
],
},
},
],
};
export default configuration;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment