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

405 and CORS #12

Closed
avalero opened this issue Aug 8, 2022 · 2 comments
Closed

405 and CORS #12

avalero opened this issue Aug 8, 2022 · 2 comments

Comments

@avalero
Copy link

avalero commented Aug 8, 2022

Hello,
I have a server configured with http as follows:

const handler = async (req: Request) => {
    const { pathname } = new URL(req.url);

    return pathname === "/graphql"
      ? await GraphQLHTTP<Request, Context>({
          schema: makeExecutableSchema({
            resolvers,
            typeDefs: [center, student, instructor, group, scalars],
          }),
          graphiql: true,
          context: () => {
            return { request: req };
          },
        })(req)
      : new Response("Not Found", { status: 404 });
  };

  const server = new Server({ handler });
  const listener = Deno.listen({ port: parseInt(PORT) });

  console.info("Listening on", listener.addr);

  await server.serve(listener);

When I use the graphiql playground it works just fine, but when using from any other client I get 2 erros:

  • Request Method: OPTIONS Status Code: 405 Method Not Allowed
  • CORS

How could I fix this? Thanks for your time.

@talentlessguy
Copy link
Member

regarding CORS I don't know why the error happens because it's not controlled by gql, but for OPTIONS it's a bug.

If you want, you can create a PR for it, or I'll fix it later myself, seems very simple to fix.

@avalero avalero mentioned this issue Aug 9, 2022
@MichaelFedora
Copy link
Contributor

MichaelFedora commented Oct 7, 2022

@avalero The solution is not from the library but from how you are handling CORS with your app.

Please see an example with CORS here: https://github.com/MichaelFedora/gql/blob/vanilla-cors/examples/vanilla.ts

--

I say this because OPTIONS is correctly handled by oak (and probably other http libraries), so if you are using vanilla, you are going to have to do it manually regardless.

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

Successfully merging a pull request may close this issue.

3 participants