All Projects → kevva → Graphql Got

kevva / Graphql Got

Licence: mit
Convenience wrapper for got to interact with GraphQL

Programming Languages

javascript
184084 projects - #8 most used programming language

graphql-got Build Status

Convenience wrapper for got to interact with GraphQL

A lightweight alternative to apollo-client and relay.

Install

$ npm install graphql-got

Usage

const graphqlGot = require('graphql-got');

const query = `{
	unicorn(name: "Foo Bar") {
		id
		name
	}
}`;

graphqlGot('api.graphql.unicorn', {query}).then(response => {
	console.log(response.body);
	/*
	{
		unicorn: {
			id: 0,
			name: 'Foo Bar'
		}
	}
	*/
});

API

Same as got, but with some additional options below. URLs without protocol will be prepended with https://.

query

Required
Type: string

The query to send to GraphQL.

variables

Type: Object

Variables to be used in your query. Read more here.

operationName

Type: string

If your query contains multiple operations, this option is required to decide which operation to run.

token

Type: string

If defined, an Authorization header with bearer ${TOKEN} will be sent.

License

MIT © Kevin Mårtensson

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].