Gathering detailed insights and metrics for @testmail.app/graphql-request
Gathering detailed insights and metrics for @testmail.app/graphql-request
Gathering detailed insights and metrics for @testmail.app/graphql-request
Gathering detailed insights and metrics for @testmail.app/graphql-request
graphql-request
Minimal GraphQL client supporting Node and browsers for scripts or simple apps.
@octokit/request
Send parameterized requests to GitHub's APIs with sensible defaults in browsers and Node
apollo-upload-client
A terminating Apollo Link for Apollo Client that fetches a GraphQL multipart request if the GraphQL variables contain files (by default FileList, File, or Blob instances), or else fetches a regular GraphQL POST or GET request (depending on the config and
graphql-upload
Middleware and a scalar Upload to add support for GraphQL multipart requests (file uploads via queries and mutations) to various Node.js GraphQL servers.
npm install @testmail.app/graphql-request
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
2 Stars
151 Commits
2 Watching
28 Branches
Updated on 16 Oct 2024
TypeScript (82.96%)
JavaScript (17.04%)
Cumulative downloads
Total Downloads
Last day
15.8%
923
Compared to previous day
Last week
6.2%
4,232
Compared to previous week
Last month
14.9%
15,868
Compared to previous month
Last year
12.6%
189,445
Compared to previous year
Clone of graphql-request (minimal GraphQL client) with improvements like built-in retries.
async
/ await
) and typescript support1npm install @testmail.app/graphql-request
1import { request } from '@testmail.app/graphql-request' 2 3const query = `{ 4 Movie(title: "Inception") { 5 releaseDate 6 actors { 7 name 8 } 9 } 10}`; 11 12request('https://api.graph.cool/simple/v1/movies', query).then(data => 13 console.log(data) 14);
1import { request, GraphQLClient } from '@testmail.app/graphql-request' 2 3// Run GraphQL queries/mutations using a static function 4request(endpoint, query, variables).then(data => console.log(data)); 5 6// ... or create a GraphQL client instance to send requests 7const client = new GraphQLClient(endpoint, { headers: {} }); 8client.request(query, variables).then(data => console.log(data)); 9 10// This is the default retry policy: 11const client = new GraphQLClient(endpoint, { 12 retries: 9, 13 retryDelay: function (attempt) { 14 // Exponential backoff: 1s, 2s, 4s, etc. upto 40s (max) 15 return Math.min(Math.pow(2, attempt) * 1000, 40000); 16 }, 17 retryOn: [500, 502, 503, 504] // response status codes to retry on 18 // network connection errors are always retried 19});
To override the default retry policy, replace any of those three arguments: retries
, retryDelay
, and retryOn
.
The options object (2nd argument to GraphQLClient constructor) passes along any additional parameters to fetch - so you can easily configure the underlying fetch API :)
1import { GraphQLClient } from '@testmail.app/graphql-request' 2 3async function main() { 4 const endpoint = 'https://api.graph.cool/simple/v1/cixos23120m0n0173veiiwrjr' 5 6 const graphQLClient = new GraphQLClient(endpoint, { 7 headers: { 8 authorization: 'Bearer MY_TOKEN', 9 }, 10 }) 11 12 const query = /* GraphQL */ ` 13 { 14 Movie(title: "Inception") { 15 releaseDate 16 actors { 17 name 18 } 19 } 20 } 21 ` 22 23 const data = await graphQLClient.request(query) 24 console.log(JSON.stringify(data, undefined, 2)) 25} 26 27main().catch(error => console.error(error))
1import { GraphQLClient } from '@testmail.app/graphql-request' 2 3async function main() { 4 const endpoint = 'https://api.graph.cool/simple/v1/cixos23120m0n0173veiiwrjr' 5 6 const graphQLClient = new GraphQLClient(endpoint, { 7 credentials: 'include', 8 mode: 'cors', 9 }) 10 11 const query = /* GraphQL */ ` 12 { 13 Movie(title: "Inception") { 14 releaseDate 15 actors { 16 name 17 } 18 } 19 } 20 ` 21 22 const data = await graphQLClient.request(query) 23 console.log(JSON.stringify(data, undefined, 2)) 24} 25 26main().catch(error => console.error(error))
1import { request } from '@testmail.app/graphql-request' 2 3async function main() { 4 const endpoint = 'https://api.graph.cool/simple/v1/cixos23120m0n0173veiiwrjr' 5 6 const query = /* GraphQL */ ` 7 query getMovie($title: String!) { 8 Movie(title: $title) { 9 releaseDate 10 actors { 11 name 12 } 13 } 14 } 15 ` 16 17 const variables = { 18 title: 'Inception', 19 } 20 21 const data = await request(endpoint, query, variables) 22 console.log(JSON.stringify(data, undefined, 2)) 23} 24 25main().catch(error => console.error(error))
1import { request } from '@testmail.app/graphql-request' 2 3async function main() { 4 const endpoint = 'https://api.graph.cool/simple/v1/cixos23120m0n0173veiiwrjr' 5 6 const query = /* GraphQL */ ` 7 { 8 Movie(title: "Inception") { 9 releaseDate 10 actors { 11 fullname # "Cannot query field 'fullname' on type 'Actor'. Did you mean 'name'?" 12 } 13 } 14 } 15 ` 16 17 try { 18 const data = await request(endpoint, query) 19 console.log(JSON.stringify(data, undefined, 2)) 20 } catch (error) { 21 console.error(JSON.stringify(error, undefined, 2)) 22 process.exit(1) 23 } 24} 25 26main().catch(error => console.error(error))
require
instead of import
1const { request } = require('graphql-request') 2 3async function main() { 4 const endpoint = 'https://api.graph.cool/simple/v1/cixos23120m0n0173veiiwrjr' 5 6 const query = /* GraphQL */ ` 7 { 8 Movie(title: "Inception") { 9 releaseDate 10 actors { 11 name 12 } 13 } 14 } 15 ` 16 17 const data = await request(endpoint, query) 18 console.log(JSON.stringify(data, undefined, 2)) 19} 20 21main().catch(error => console.error(error))
The request
method will return the data
or errors
key from the response.
If you need to access the extensions
key you can use the rawRequest
method:
1import { rawRequest } from '@testmail.app/graphql-request' 2 3async function main() { 4 const endpoint = 'https://api.graph.cool/simple/v1/cixos23120m0n0173veiiwrjr' 5 6 const query = /* GraphQL */ ` 7 { 8 Movie(title: "Inception") { 9 releaseDate 10 actors { 11 name 12 } 13 } 14 } 15 ` 16 17 const { data, errors, extensions, headers, status } = await rawRequest( 18 endpoint, 19 query 20 ) 21 console.log( 22 JSON.stringify({ data, errors, extensions, headers, status }, undefined, 2) 23 ) 24} 25 26main().catch(error => console.error(error))
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
30 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More