Skip to content

Why does RequestHeaders have the get key? #99

Answered by enisdenjo
aarontravass asked this question in Q&A
Discussion options

You must be logged in to vote

graphql-http has its own Request, you cannot override it. You can either:

import { createHandler } from 'graphql-http';

const handler = createHandler({
  context: (req) => ({
    auth:
      typeof req.headers.get === 'function'
        ? req.headers.get('authorization')
        : Object(req.headers).authorization,
  }),
});

or

import { createHandler } from 'graphql-http';
import type { Request } from '@tinyhttp/app';

const handler = createHandler<Request>({
  context: (req) => ({
    auth: req.raw.headers.authorization,
  }),
});

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@aarontravass
Comment options

@enisdenjo
Comment options

Answer selected by aarontravass
@aarontravass
Comment options

@enisdenjo
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants