Running into a challenge while using the graphql-request module from Prisma Labs. Specifically, I am unsure of how to define certain options using typescript.
In my request, there are 2 headers that need to be defined:
interface GraphQLHeaders {
'X-Api-Key'?: string
'X-Account-Id'?: string
}
However, when attempting to define these headers in TypeScript, I encounter errors:
const headers: GraphQLHeaders = {}
if(apiKey)
headers['X-Api-Key'] = apiKey
const client = new GraphQLClient(apiUrl, { headers })
The error message reads:
Type 'GraphQLHeaders' is not assignable to type 'Headers | string[][] | Record<string, string> | undefined'.
Type 'GraphQLHeaders' is not assignable to type 'Record<string, string>'.
Index signature is missing in type 'GraphQLHeaders'
I am seeking guidance on the correct approach for restricting the headers to certain fields while still being able to pass them successfully. Any suggestions?