-
-
Save vedovelli/87170434cbc08998fcf97272b3b32068 to your computer and use it in GitHub Desktop.
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
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; | |
} | |
); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment