Skip to content

Instantly share code, notes, and snippets.

@lorefnon
Created November 25, 2019 18:13
Show Gist options
  • Save lorefnon/03376aa4234f041cca92b24bee38fae0 to your computer and use it in GitHub Desktop.
Save lorefnon/03376aa4234f041cca92b24bee38fae0 to your computer and use it in GitHub Desktop.
GRelDAL custom operations without Database interactions
const { mapSchema } = require("greldal");
const { graphql, GraphQLString } = require("graphql");
const customOperation = {
operationType: "query",
name: "printHello",
fieldConfig: {
type: GraphQLString,
description: "Prints hello",
resolve: (obj, args, context, info) => {
return "hello";
}
}
}
const customOperationWithArgs = {
operationType: "query",
name: "printGreeting",
fieldConfig: {
type: GraphQLString,
args: {
name: {
type: GraphQLString,
defaultValue: "Markus"
}
},
description: "Prints hello",
resolve: (obj, args, context, info) => {
return `hello ${args.name}`;
}
}
}
const generatedSchema = mapSchema([
customOperation,
customOperationWithArgs
]);
(async () => {
const result1 = await graphql(generatedSchema, `
query {
printHello
}
`);
console.log('result1: ', result1);
const result2 = await graphql(generatedSchema, `
query {
printGreeting
}
`);
console.log('result2: ', result2);
const result3 = await graphql(generatedSchema, `
query {
printGreeting(name: "Lorefnon")
}
`);
console.log('result3: ', result3);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment