Skip to content

Instantly share code, notes, and snippets.

@jbaxleyiii
Created April 3, 2018 05:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbaxleyiii/7f1954e346baaec1f71093137b41946e to your computer and use it in GitHub Desktop.
Save jbaxleyiii/7f1954e346baaec1f71093137b41946e to your computer and use it in GitHub Desktop.
const { ApolloServer, gql, Connector } = require("apollo-server");
const users = [{ id: 1, firstName: "James" }];
class UserConnector {
getById(id) {
return users.find(user => user.id == id);
}
}
let votes = 0;
const server = new ApolloServer({
typeDefs: gql`
type Query {
users: [User]
foo: Foo
votes: Int
}
type UpVoteReponse @mutationResponse {
votes: Int
}
type Mutation {
upvote: UpVoteReponse
}
type Foo {
id: ID! @unique
}
type User @node {
firstName: String
}
`,
resolvers: {
Query: {
users: () => users,
foo: () => ({ id: 1 }),
votes: () => votes,
},
Mutation: {
upvote: () => {
votes++;
return { votes };
},
},
},
context: async ({ request }) => ({
connectors: { User: new UserConnector() },
}),
});
server.listen();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment