Created
December 4, 2019 17:19
-
-
Save samselikoff/0e176a76e5be53cbb94e85020fc2b115 to your computer and use it in GitHub Desktop.
Revisions
-
samselikoff created this gist
Dec 4, 2019 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,54 @@ import { buildSchema, graphql } from "graphql"; // Construct a schema, using GraphQL schema language let graphqlSchema = buildSchema(` type Query { recipes: [Recipe] recipes_by_pk(id: Int!): Recipe } type Recipe { id: ID! name: String! imageUrl: String recipeUrl: String ingredients: String instructions: String } type recipes_insert_input { id: Int imageUrl: String ingredients: String instructions: String name: String recipeUrl: String } type Mutation { insert_recipes(objects: [recipes_insert_input!]!): Recipe! } `); export default function() { this.urlPrefix = "https://samselikoff-recipes-backend.herokuapp.com"; this.post("/v1/graphql", (schema, request) => { let requestJson = JSON.parse(request.requestBody); let query = requestJson.query; let variables = requestJson.variables; let resolver = { recipes() { return schema.db.recipes; }, recipes_by_pk(args) { return schema.db.recipes.find(args.id); } }; return graphql(graphqlSchema, query, resolver, null, variables).then( response => { return response; } ); }); }