Skip to content

Instantly share code, notes, and snippets.

@JeffML
Created April 8, 2018 17:15
Show Gist options
  • Save JeffML/f4592fa89541b097c1c8477d6045e43b to your computer and use it in GitHub Desktop.
Save JeffML/f4592fa89541b097c1c8477d6045e43b to your computer and use it in GitHub Desktop.
A simple schema and resolver for demonstrating parallel vs sequential execution
import {makeExecutableSchema} from 'graphql-tools';
const typeDefs = `
type Query {
message(id: ID!): String!
}
type Mutation {
message(id: ID!): String!
}
`
const resolvers = {
Query: {
message: (_, {id}) => new Promise(resolve => {
setTimeout(function() {
let message = `response to message ${id}`;
console.log(message)
resolve(message);
}, Math.random() * 10000)
})
},
Mutation: {
message: (_, {id}) => new Promise(resolve => {
setTimeout(function() {
let message = `response to message ${id}`;
console.log(message)
resolve(message);
}, Math.random() * 10000)
})
}
}
const schema = makeExecutableSchema({typeDefs, resolvers});
export {
schema
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment