Created
May 19, 2018 08:29
-
-
Save dh94/1dec5c54ecdb9c20e52985fff4ccaa6b to your computer and use it in GitHub Desktop.
graphql-tools merged Subscription schema
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 { | |
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