Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

apollo-server-plugin-http-headers

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apollo-server-plugin-http-headers - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

2

package.json
{
"name": "apollo-server-plugin-http-headers",
"version": "0.1.0",
"version": "0.1.1",
"description": "Allows you to set HTTP Headers and Cookies easily in your apollo server resolvers.",

@@ -5,0 +5,0 @@ "main": "src/index.js",

# apollo-server-plugin-http-headers
Allows you to set HTTP Headers and Cookies easily in your resolvers. This is especially useful in apollo-server-lambda, because you don't have any other options there to set headers or cookies.

@@ -7,45 +8,58 @@

## Installation
- First, install the package:
`npm install apollo-server-plugin-http-headers`
- Register the plugin and add setHeaders and setCookies to context:
```javascript
const httpHeadersPlugin = require("apollo-server-plugin-http-headers");
const server = new ApolloServer({
typeDefs,
resolvers,
plugins: [httpHeadersPlugin],
context: {
### Install the package
`npm install apollo-server-plugin-http-headers`
### Register plugin
Import and register the plugin, then add `setHeaders` and `setCookies` to context:
```javascript
const httpHeadersPlugin = require("apollo-server-plugin-http-headers");
const server = new ApolloServer({
typeDefs,
resolvers,
plugins: [httpHeadersPlugin],
context: {
setCookies: new Array(),
setHeaders: new Array()
}
});
```
Please note: The context argument varies depending on the specific integration (e.g. Express, Koa, Lambda, etc.) being used. See the [official apollo-server documentation](https://www.apollographql.com/docs/apollo-server/api/apollo-server/) for more details.
Example for the Lambda integration (apollo-server-lambda):
```javascript
const httpHeadersPlugin = require("apollo-server-plugin-http-headers");
const server = new ApolloServer({
typeDefs,
resolvers,
plugins: [httpHeadersPlugin],
context: ({ event, context }) => {
return {
event,
context,
setCookies: new Array(),
setHeaders: new Array()
}
});
```
Please note: The context argument varies depending on the specific integration (e.g. Express, Koa, Lambda, etc.) being used. See the [official apollo-server documentation](https://www.apollographql.com/docs/apollo-server/api/apollo-server/) for more details.
Example for the Lambda integration (apollo-server-lambda):
```javascript
const httpHeadersPlugin = require("apollo-server-plugin-http-headers");
const server = new ApolloServer({
typeDefs,
resolvers,
plugins: [httpHeadersPlugin],
context: ({ event, context }) => {
return {
event,
context,
setCookies: new Array(),
setHeaders: new Array()
};
}
});
```
};
}
});
```
## Usage
### Headers
Set a header in a resolver:
```javascript
context.setHeaders.push({ key: "headername", value: "headercontent" });
```
Complete example:
```javascript

@@ -64,3 +78,5 @@ const resolvers = {

### Cookies
Set a cookie in a resolver:
```javascript

@@ -81,3 +97,5 @@ context.setCookies.push({

```
Complete example:
```javascript

@@ -87,3 +105,3 @@ const resolvers = {

hello: async (parent, args, context, info) => {
context.setCookies.push({

@@ -102,3 +120,3 @@ name: "cookieName",

});
return "Hello world!";

@@ -109,4 +127,7 @@ }

```
#### Cookie Options
This package uses [jshttp/cookie](https://github.com/jshttp/cookie) for serializing cookies and you can use all the options they provide. Find an overview below or the complete documentation [here](https://github.com/jshttp/cookie#cookieserializename-value-options).
option | description

@@ -113,0 +134,0 @@ --- | ---

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc