Skip to content

Instantly share code, notes, and snippets.

@bbg
Created June 21, 2020 15:29
Show Gist options
  • Save bbg/9eebfdc9f2094654353e5a7cd2c783b1 to your computer and use it in GitHub Desktop.
Save bbg/9eebfdc9f2094654353e5a7cd2c783b1 to your computer and use it in GitHub Desktop.
import { ApolloServer, AuthenticationError, gql } from "apollo-server"
// API's
import Dashboard from "@root/api/dashboard"
import General from "@root/api/general"
import Assets from "@root/api/assets"
import { importSchema } from "graphql-import"
const GraphQLServer = new ApolloServer({
typeDefs: `
input UserAuthInput { email: String password: String }
type UserAuthType { status: Int description: String database_message: String user: UserType_ }
type Mutation {
CreateUser(payload: UserAuthInput): UserAuthType
}
`
resolvers: {
Mutation: {
CreateUser: async (_, { payload }) => CreateUser({ payload: payload }),
}
},
introspection: true,
playground: true,
cors: {
origin: "*",
methods: "GET, HEAD, PUT, PATCH, POST, DELETE",
preflightContinue: false,
optionsSuccessStatus: 204,
credentials: true
},
context: ({ req }) => {
// // get the user token from the headers
// const token = req.headers.authentication || ''
// // try to retrieve a user with the token
// const user = null
// // optionally block the user
// // we could also check user roles/permissions here
// if (!user) throw new AuthenticationError('you must be logged in')
// // add the user to the context
// return { user }
}
})
GraphQLServer.listen().then(({ url }) => {
console.log(`🚀 Server ready at ${url}`)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment