Skip to content

Instantly share code, notes, and snippets.

@danstarns
Last active December 29, 2019 19:57
Show Gist options
  • Select an option

  • Save danstarns/029500e68b627d4bd51ea0f2ea768d96 to your computer and use it in GitHub Desktop.

Select an option

Save danstarns/029500e68b627d4bd51ea0f2ea768d96 to your computer and use it in GitHub Desktop.
idio-graphql dependency injection
const { combineNodes, GraphQLNode } = require("idio-graphql");
const { ApolloServer } = require("apollo-server");
const gql = require("graphql-tag");
const User = new GraphQLNode({
name: "User",
typeDefs: gql`
type User {
name: String
}
type Query {
user: User
}
`,
injections: {
prefix: "the cat called"
},
resolvers: {
Query: {
user: (root, args, { injections }) => {
return { name: `${injections.prefix} dasiy` };
}
}
}
});
async function main() {
try {
const { typeDefs, resolvers } = await combineNodes([User]);
const server = new ApolloServer({
typeDefs,
resolvers
});
await server.listen(4000);
console.log(`Server up on port 4000 🚀`);
} catch (error) {
console.error(error);
}
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment