Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrating with Apollo Server #133

Open
ghiblin opened this issue Nov 27, 2018 · 4 comments
Open

Integrating with Apollo Server #133

ghiblin opened this issue Nov 27, 2018 · 4 comments

Comments

@ghiblin
Copy link

ghiblin commented Nov 27, 2018

Hi,

I'd like to integrate ReactQL Koa Server with an Apollo Server.
I've tried to setup a middleware ad described in the server documentation just before the router middleware in the /src/runner/app.ts file, but that does not work.
Any ideas?

Thank you

@leebenson
Copy link
Owner

@ghiblin - please post some code. Hard to diagnose without it.

@ghiblin
Copy link
Author

ghiblin commented Nov 28, 2018

I've defined a basic apollo server:

// apollo.ts
import { ApolloServer, gql } from "apollo-server-koa";

// Construct a schema, using GraphQL schema language
const typeDefs = gql`
  type Query {
    hello: String
  }
`;

// Provide resolver functions for your schema fields
const resolvers = {
  Query: {
    hello: () => "Hello world!",
  },
};

const server = new ApolloServer({ typeDefs, resolvers });
export default server;

then in runner/app.ts I've imported it and tried to setup the middleware with import apollo from './apollo'; apollo.applyMiddleware({ app });
I've placed this line of code in different point (just after app initialization, before static middleware or router), but when I point to http://localhost:8080/graphql I don't see graphql playground, but my layout page.

Any ideas?

@ghiblin
Copy link
Author

ghiblin commented Dec 3, 2018

I found a solution with a monkey patch: in entry/server.tsx I check for ctx.path

  // Create Koa middleware to handle React requests
  return async (ctx: Context, next: () => Promise<any>) => {
    ...
    if (ctx.path === "/graphql") {
      return next();
    }
    ...
}

In this way I can access to apollo server playground on http://localhost:3000/graphql, but it's not the way to resolve this issue. I think I have to create a new entry in src/entry and then import it in src/runner/development,ts. Is it correct?

@ZimboQC
Copy link

ZimboQC commented Feb 1, 2019

I'm trying to use the koa context in GraphQL, but it doesn't pass through even with context: ({ ctx }:any) => ctx, in ApolloServer option.
Does anyone got it working?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants