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

Apollo context type #14

Open
Fxlr8 opened this issue Aug 12, 2024 · 0 comments
Open

Apollo context type #14

Fxlr8 opened this issue Aug 12, 2024 · 0 comments

Comments

@Fxlr8
Copy link

Fxlr8 commented Aug 12, 2024

It seems like the context types are hanlded incorrectly.
According to the apollo documentation the context function that is passed to the plugin should receive web server's context and return some custom user context.

When I do this:

interface MyContext {
  user: {
    id: number
  }
}

app.use(
  apollo<'/graphql', MyContext>({
    typeDefs: schema,
    resolvers,
    context: async (elysiaContext: Context) => {

      const token = elysiaContext?.headers?.get('Authorization')
      const user = parseUser(token)

      return {
        user
      }
    }
  })
)

I expect elysiaContext to be Context type from Elysia. But If I don't provide any type like that

app.use(
  apollo<'/graphql'>({
  ...

elysiaContext argument will have Apollo BaseContext type which is an empty object by default

But if I log the elysiaContext object it has request field and many more:

{
  request: Request (0 KB) {
    method: "POST",
    url: "http://localhost:3000/graphql",
    headers: Headers {
      ...
    }
  },
  store: {},
  set: {
    headers: {
      ...
    },
    status: 200,
    cookie: {},
  },
  error: [Function: error],
  qi: -1,
  path: "/graphql",
  headers: {
    ...
  },
  query: {},
  body: {
    operationName: "IntrospectionQuery",
    variables: {},
    query: "query ...",
  },
}

What is that? Where does it come from?

I think the types could use a refactor here. Do you need help with that?

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

1 participant