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

Feature Request: GraphQL support #1307

Open
oo00spy00oo opened this issue Aug 3, 2024 · 1 comment
Open

Feature Request: GraphQL support #1307

oo00spy00oo opened this issue Aug 3, 2024 · 1 comment

Comments

@oo00spy00oo
Copy link

How to implement GraphQL support in Encore?

Take a look at: https://github.com/dotansimha/graphql-yoga

@seivan
Copy link

seivan commented Aug 15, 2024

How to implement GraphQL support in Encore?

Take a look at: https://github.com/dotansimha/graphql-yoga

Implement a raw API call and massage the request type from encore to fit yogas requirements and response to fit whatever encore wants.

Maybe it's raw node req/responses or Express or https://developer.mozilla.org/en-US/docs/Web/API/Request

mport { createYoga } from 'graphql-yoga'
 
const yoga = createYoga<SomeContext>()
 
export async function serveGraphQLRequest(req: WhatEverRequestEncoreGives, ctx: SomeContext) -> WhateverResponseEncoreExpects {
  const response = await yoga.fetch(
    req.url,
    {
      method: req.method,
      headers: req.headers,
      body: req.body 
    },
    ctx
  )
 
  const headersObj = Object.fromEntries(response.headers.entries())
 
  // Let's say your environment needs to return something like the below;
const encoreResponse: WhateverResponseEncoreExpects =  {
    statusCode: response.status,
    body: response.body,
    headers: headersObj 
  }
return encoreResponse

}

export const graphQLApiPoint = api.raw(
  { expose: true, path: "/api/gql", method: "POST" },
  async (req, resp) => {
  return  serveGraphQLRequest(req) // Let the type checker help you. 
  },
);

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

2 participants