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
var possibleTypes = schema.data.__schema.types | |
.filter(supertype => supertype.possibleTypes) | |
.reduce((all, supertype) => { | |
all[supertype.name] = supertype.possibleTypes.map(subtype => subtype.name); | |
return all; | |
}, {}); |
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
export const types = ` | |
type User { | |
id: ID | |
email: String | |
password: String | |
loggedIn: Boolean | |
firstName: String | |
lastName: String | |
} | |
`; |
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 queries = { | |
user: (root, args) => { | |
return { | |
id: "12345", | |
email: "some.user@email.com", | |
password: "Pa$$w0rd!", | |
loggedIn: false, | |
firstName: "Some", | |
lastName: "User", | |
}; |
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
export const queries = ` | |
user(id: String!) : User | |
`; |
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
export const mutations = ` | |
createUser( | |
email: String! | |
password: String! | |
firstName: String! | |
lastName: String! | |
): User | |
`; |
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 { queries } from "./queries.js" | |
import { mutations } from "./mutations.js" | |
import { resolvers } from "./resolvers.js" | |
import { types } from "./types" | |
export const User = { queries, mutations, resolvers, types } | |
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 { gql } from "apollo-server-express"; | |
import { User } from "./User"; | |
const typeDefs = gql` | |
${User.types} | |
type Query { | |
${User.queries} | |
} | |
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 { User } from './User' | |
const resolvers = { | |
Query: { | |
...User.resolvers.queries, | |
}, | |
Mutation: { | |
...User.resolvers.mutations, | |
} | |
}; |
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
export { default as typeDefs } from './typeDefs' | |
export { default as resolvers } from './resolvers' |
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 express from 'express' | |
import { ApolloServer } from 'apollo-server-express' | |
import { typeDefs, resolvers } from '../graphql' | |
const server = new ApolloServer({ | |
typeDefs, | |
resolvers, | |
introspection: true, | |
playground: true | |
}) |
NewerOlder