Created
April 3, 2018 05:39
-
-
Save jbaxleyiii/7f1954e346baaec1f71093137b41946e 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
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