graffle-js/graffle
Fork: 308 Star: 5846 (更新于 2024-10-24 21:45:19)
license: MIT
Language: TypeScript .
Simple GraphQL Client for JavaScript. Minimal. Extensible. Type Safe. Runs everywhere.
最后发布版本: 7.1.0 ( 2024-06-22 10:41:17)
[!IMPORTANT] The next version (
8
) ofgraphql-request
is being renamed tograffle
. It has the same base simplicity but with many fixes, enhancements, and major new type safe features. It is not released yet but will be in the coming weeks/months and is already usable. Learn more about it here. You can see the in progress website at https://graffle.js.org.The following README is still for
graphql-request@7.x.x
graphql-request
Minimal GraphQL client supporting Node and browsers for scripts or simple apps.
Highlights
- Most simple & lightweight GraphQL client
- Promise-based API (works with
async
/await
) - Pure ESM package
- First class TypeScript support
- Including
TypedDocumentNode
- Including
- Isomorphic (works in both Node and Browsers)
Install
npm add graffle graphql
TypeScript Setup
This package uses package.exports
. Therefore if you are a TypeScript user you must:
- have your
tsconfig.json
moduleResolution
set to"bundler"
or"node16"
/"nodenext"
. - Have your
package.json
type
set to"module"
.
Quick Start
Send a GraphQL document using a static request function:
import { gql, request } from 'graffle'
const document = gql`
{
company {
ceo
}
}
`
await request('https://api.spacex.land/graphql/', document)
The function can be passed a configuration object for more complex cases:
await request({
url,
document,
variables,
requestHeaders,
})
A class is available for constructing your own instances:
import { gql, GraphQLClient } from 'graffle'
const document = gql`
{
company {
ceo
}
}
`
const endpoint = 'https://api.spacex.land/graphql/'
const client = new GraphQLClient(endpoint)
await client.request(document)
Examples
- Request:
- GraphQL:
- Configuration:
- TypeScript:
- Other:
Node Version Support
We only (officially) support versions of Nodejs of the following status:
- Current
- LTS
- Maintenance and end of life not yet reached
So for example on Oct 24 2023 that would mean these versions: 18, 20, 21.
Any issue that exists solely for an unsupported version of Nodejs will be rejected (not worked on).
Reference
⚠️ This reference is incomplete. Check out the examples for more reference material.
Configuration
ErrorPolicy
By default GraphQLClient will throw when an error is received. However, sometimes you still want to resolve the (partial) data you received.
You can define errorPolicy
in the GraphQLClient
constructor.
const client = new GraphQLClient(endpoint, { errorPolicy: 'all' })
None (default)
Allow no errors at all. If you receive a GraphQL error the client will throw.
Ignore
Ignore incoming errors and resolve like no errors occurred
All
Return both the errors and data, only works with rawRequest
.
IgnoreOperationName
OperationName has been introduced to address issues reported here Support operation name, However, on certain occasions this information may not be needed in requests. In such cases, you might consider ignoring operationName to avoid the extraction steps currently performed by a parsing operation when the document is provided in string format.
By default the GraphQLClient tries to extract the operationName from the document.
You can define excludeOperationName
in the constructor of GraphQLClient to avoid the extraction process if it is not needed. This can be useful if you don't use operationName and want to optimise queries by reducing the amount of computation as much as possible, especially if we are in a context where we are using documents in string format to reduce bundle size.
// example where the operation name is not ignored
const client = new GraphQLClient(endpoint, {
method: 'POST',
})
// example in which the operation name is ignored
const client = new GraphQLClient(endpoint, {
method: 'POST',
excludeOperationName: true,
})
Knowledge Base
Why was the file upload feature taken away? Will it return?
In this issue we decided to make this library more stable and maintainable. In principal the feature is still in scope of this library and will make a return when we find time to do the feature right.
Why do I have to install graphql
?
graffle
uses methods exposed by the graphql
package to handle some internal logic. On top of that, for TypeScript users, some types are used from the graphql
package to provide better typings.
Do I need to wrap my GraphQL documents inside the gql
template exported by graffle
?
No. It is there for convenience so that you can get the tooling support like automatic formatting and syntax highlighting. You can use gql
from graphql-tag
if you need it for some reason too.
What sets graffle
apart from other clients like Apollo, Relay, etc.?
graffle
is the most minimal and simplest to use GraphQL client. It's perfect for small scripts or simple apps.
Compared to GraphQL clients like Apollo or Relay, graffle
doesn't have a built-in cache and has no integrations for frontend frameworks. The goal is to keep the package and API as minimal as possible.
Project Stats
Package Installs
Repo Beats
最近版本更新:(数据更新于 2024-09-15 11:01:03)
2024-06-22 10:41:17 7.1.0
2024-05-11 12:34:40 7.0.1
2024-05-09 10:18:25 7.0.0
2023-05-24 00:56:08 6.1.0
2023-04-13 11:54:33 6.0.0
2023-03-02 00:18:40 5.2.0
2022-08-27 21:47:06 5.0.0
2022-03-23 20:49:25 4.0.0
2022-03-23 20:37:48 4.2.0
2022-03-11 00:57:34 4.1.0
主题(topics):
graphql, graphql-client, graphql-request, lightweight, nodejs, typescript
graffle-js/graffle同语言 TypeScript最近更新仓库
2024-11-05 17:55:23 langgenius/dify
2024-11-05 17:35:52 siyuan-note/siyuan
2024-11-05 16:59:32 laurent22/joplin
2024-11-05 12:39:27 lobehub/lobe-chat
2024-11-05 11:52:31 RSSNext/Follow
2024-11-05 07:18:03 microsoft/genaiscript