Skip to content

Instantly share code, notes, and snippets.

@dh94
Created May 19, 2018 08:29
Show Gist options
  • Save dh94/1dec5c54ecdb9c20e52985fff4ccaa6b to your computer and use it in GitHub Desktop.
Save dh94/1dec5c54ecdb9c20e52985fff4ccaa6b to your computer and use it in GitHub Desktop.
graphql-tools merged Subscription schema
import {
makeExecutableSchema,
mergeSchemas,
} from 'graphql-tools';
import { PubSub } from 'graphql-subscriptions';
const simpleSchema = makeExecutableSchema({
typeDefs: `
type Query {
_blank: String
}
`,
resolvers: {
Query: {
_blank: () => 'helloWorld',
},
},
});
const pubsub = new PubSub();
const subscriptionSchema = makeExecutableSchema({
typeDefs: `
type Query {
_blank2: String
}
type TimeQuery {
time: String
throwError: Boolean
}
type Subscription {
tellMeTime: TimeQuery
}
`,
resolvers: {
Subscription: {
tellMeTime: {
subscribe: () => pubsub.asyncIterator('time'),
},
},
TimeQuery: {
throwError: () => { throw new Error(); },
},
},
});
setInterval(() => {
pubsub.publish('time', {
tellMeTime: {
time: new Date().toLocaleTimeString(),
},
});
}, 1000);
export const schema = mergeSchemas({
schemas: [
simpleSchema,
subscriptionSchema,
],
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment