Passing headers
HTTP header fields are a collection of strings that are transmitted and received by both the client program and server with each HTTP request and response. Typically, these headers remain hidden from the end user and are solely handled or recorded by the server and client applications.
Since both GraphQL and REST operate based on HTTP, there isn’t much difference in passing headers between them by the consumer of our system. However, header validation in REST is done at a specific endpoint, while in GraphQL, it is done at specific resolvers.
In our todo
management REST proxy, we can simply pass those headers like this:
getTodoById: async (p,args) => { if(cachedTodosList.object){ return (cachedTodosList.object as {id:number}[]).find(o => o.id === args.id) ...