Skip to content

Instantly share code, notes, and snippets.

@jtmarmon
Created October 23, 2015 20:48
Show Gist options
  • Save jtmarmon/31682c4244d777d4fe68 to your computer and use it in GitHub Desktop.
Save jtmarmon/31682c4244d777d4fe68 to your computer and use it in GitHub Desktop.
import {parse, Source} from 'graphql/language'
import {GraphQLSchema, GraphQLObjectType, GraphQLString} from 'graphql/type'
import {graphql} from 'graphql'
const whisperType = new GraphQLObjectType({
name: 'Whisper',
fields: () => ({
whyAreYouWhispering: {
type: GraphQLString
}
})
})
const screamType = new GraphQLObjectType({
name: 'Scream',
fields: () => ({
dudeWhyAreYouScreaming: {
type: GraphQLString
}
})
})
const schema = new GraphQLSchema ({
// you can ignore this...graphql just wants to me to have a query
query: new GraphQLObjectType({ name: 'RootQueryType', fields: { fooQuery: { type: whisperType, resolve: source => source } } }),
subscription: new GraphQLObjectType({
name :'Subscription',
fields: {
whispers: {
type: whisperType,
resolve: source => source
},
screams: {
type: screamType,
resolve: source => source
}
}
})
});
const query = `
subscription ListenWhispers {
whispers {
whyAreYouWhispering
}
}
subscription ListenScreams {
screams {
dudeWhyAreYouScreaming
}
}
`;
const rootVal = {whyAreYouWhispering: 'the baby is sleeping'};
graphql(schema, query, rootVal, {}, 'ListenWhispers').then(console.log);
// => { data: { whispers: { whyAreYouWhispering: 'the baby is sleeping' } } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment