Created
October 23, 2015 20:48
-
-
Save jtmarmon/31682c4244d777d4fe68 to your computer and use it in GitHub Desktop.
This file contains 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 {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