Skip to content

Instantly share code, notes, and snippets.

@donedgardo
Created November 3, 2018 20:56
Show Gist options
  • Select an option

  • Save donedgardo/ed2d36f6e650991543e5a55c77cddc0d to your computer and use it in GitHub Desktop.

Select an option

Save donedgardo/ed2d36f6e650991543e5a55c77cddc0d to your computer and use it in GitHub Desktop.
Apollo-server 2.0 setup graphqlshield
import { ApolloServer } from "apollo-server-express";
import { importSchema } from "graphql-import";
import { makeExecutableSchema } from "graphql-tools";
import { applyMiddleware } from "graphql-middleware";
import * as path from "path";
import { Prisma } from "./generated/prisma";
import resolvers from "./resolvers";
import permisions from "./resolvers/permisions";
export const db: Prisma = new Prisma({
endpoint: process.env.PRISMA_ENDPOINT, // the endpoint of the Prisma API (value set in `.env`)
debug: process.env.NODE_ENV === "DEBUG", // log all GraphQL queries & mutations sent to the Prisma API
secret: process.env.PRISMA_MANAGEMENT_API_SECRET // only needed if specified in `database/prisma.yml` (value set in `.env`)
});
const typeDefs: any = importSchema(path.resolve("src/schema.graphql"));
const schema = applyMiddleware(
makeExecutableSchema({
typeDefs,
resolvers
}),
permisions
);
export const server = new ApolloServer({
// Removed from Graphql Yoga but might include after PR: https://github.com/apollographql/apollo-server/pull/1799
// middlewares: [permisions],
// resolverValidationOptions: {
// requireResolversForResolveType: false
// },
typeDefs,
resolvers,
schema,
engine: {
apiKey: process.env.YOUR_APOLLO_ENGINE_KEY
},
context: req => ({
...req,
db
})
});
@ph3b
Copy link
Copy Markdown

ph3b commented Nov 16, 2018

I'm getting Error: The introspection query is resolving asynchronously; execution of an introspection query is not expected toreturn a Promise. when adding the permissions-middleware. Have you run into the same error?

Copy link
Copy Markdown

ghost commented Nov 20, 2018

I'm getting the same error

@Gomah
Copy link
Copy Markdown

Gomah commented Nov 23, 2018

If you're getting an error with the introspection query resolving asynchronously, you can fix that by downgrading the version of apollo-server until this issue is fixed: apollographql/apollo-server#1935 (related to: apollographql/apollo-server#1934)

@montnyc
Copy link
Copy Markdown

montnyc commented Nov 30, 2018

Getting the same error, except only when deploying to on my docker container... Locally, no issues 😕
Edit: @Gomah which version did you downgrade apollo-server to?

@ankitjain-xyz
Copy link
Copy Markdown

@constmontague 2.0.5

@dortamiguel
Copy link
Copy Markdown

dortamiguel commented Dec 6, 2018

any fix for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment