当前位置: 首页 > 软件库 > 大数据 > 数据查询 >

graphql-react

授权协议 Readme
开发语言 Java
所属分类 大数据、 数据查询
软件类型 开源软件
地区 不详
投 递 者 勾俊
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

graphql-react

CI status

A GraphQL client for React using modern context and hooks APIs that’s lightweight (< 4 kB) but powerful; the first Relay and Apollo alternative with server side rendering.

The API can also be used to custom load, cache and server side render any data, even from non-GraphQL sources.

Setup

First, polyfill any required globals (see Support) that are missing in your server and client environments.

Next.js setup

See the next-graphql-react setup instructions.

Custom React setup

To install with npm, run:

npm install graphql-react

Create a single Cache instance and use the Provider component to provide it for your app.

To server side render your app, use the waterfallRender function from react-waterfall-render.

Examples

Here is a basic example using the GitHub GraphQL API, with tips commented:

// While named imports are available, deep imports result in a small bundle size
// regardless of the (often dubious) tree-shaking abilities of your bundler.
import useAutoLoad from 'graphql-react/public/useAutoLoad.js';
import useCacheEntry from 'graphql-react/public/useCacheEntry.js';
import useLoadGraphQL from 'graphql-react/public/useLoadGraphQL.js';
import useWaterfallLoad from 'graphql-react/public/useWaterfallLoad.js';
import { useCallback } from 'react';

// The query is just a string; no need to use `gql` from `graphql-tag`. The
// special comment before the string allows editor syntax highlighting, Prettier
// formatting and linting. The cache system doesn’t require `__typename` or `id`
// fields to be queried.
const query = /* GraphQL */ `
  query ($repoId: ID!) {
    repo: node(id: $repoId) {
      ... on Repository {
        stargazers {
          totalCount
        }
      }
    }
  }
`;

export default function GitHubRepoStars({ repoId }) {
  const cacheKey = `GitHubRepoStars-${repoId}`;
  const cacheValue = useCacheEntry(cacheKey);

  // A hook for loading GraphQL is available, but custom hooks for loading non
  // GraphQL (e.g. fetching from a REST API) can be made.
  const loadGraphQL = useLoadGraphQL();

  const load = useCallback(
    () =>
      // To be DRY, utilize a custom hook for each API your app loads from, e.g.
      // `useLoadGraphQLGitHub`.
      loadGraphQL(
        cacheKey,
        // Fetch URI.
        'https://api.github.com/graphql',
        // Fetch options.
        {
          method: 'POST',
          headers: {
            'Content-Type': 'application/json',
            Accept: 'application/json',
            Authorization: `Bearer ${process.env.GITHUB_ACCESS_TOKEN}`,
          },
          body: JSON.stringify({
            query,
            variables: {
              repoId,
            },
          }),
        }
      ),
    [cacheKey, loadGraphQL, repoId]
  );

  // This hook automatically keeps the cache entry loaded from when the
  // component mounts, reloading it if it’s staled or deleted. It also aborts
  // loading if the arguments change or the component unmounts; very handy for
  // auto-suggest components!
  useAutoLoad(cacheKey, load);

  // Waterfall loading can be used to load data when server side rendering,
  // enabled automagically by `next-graphql-react`. To learn how this works or
  // to set it up for a non-Next.js app, see:
  // https://github.com/jaydenseric/react-waterfall-render
  const isWaterfallLoading = useWaterfallLoad(cacheKey, load);

  // When waterfall loading it’s efficient to skip rendering, as the app will
  // re-render once this step of the waterfall has loaded. If more waterfall
  // loading happens in children, those steps of the waterfall are awaited and
  // the app re-renders again, and so forth until there’s no more loading for
  // the final server side render.
  return isWaterfallLoading
    ? null
    : cacheValue
    ? cacheValue.errors
      ? // Unlike many other GraphQL libraries, detailed loading errors are
        // cached and can be server side rendered without causing a
        // server/client HTML mismatch error.
        'Error!'
      : cacheValue.data.repo.stargazers.totalCount
    : // In this situation no cache value implies loading. Use the
      // `useLoadingEntry` hook to manage loading in detail.
      'Loading…';
}

Support

  • Node.js: ^12.20 || >= 14.13
  • Browsers: > 0.5%, not OperaMini all, not IE > 0, not dead

Consider polyfilling:

API

class Cache

Cache store.

Parameter Type Description
store object? = {} Initial cache store. Useful for hydrating cache data from a server side render prior to the initial client side render.

Examples

Ways to import.

import { Cache } from 'graphql-react';
import Cache from 'graphql-react/public/Cache.js';

Ways to require.

const { Cache } = require('graphql-react');
const Cache = require('graphql-react/public/Cache.js');

Construct a new instance.

const cache = new Cache();

Cache instance property store

Store of cache keys and values.

Type: object

Cache event delete

Signals that a cache store entry was deleted. The event name starts with the cache key of the deleted entry, followed by /delete.

Type: CustomEvent

Cache event prune

Signals that a cache store entry will be deleted unless the event is canceled via event.preventDefault(). The event name starts with the cache key of the entry being pruned, followed by /prune.

Type: CustomEvent

Cache event set

Signals that a cache store entry was set. The event name starts with the cache key of the set entry, followed by /set.

Type: CustomEvent

Property Type Description
detail object Event detail.
detail.cacheValue CacheValue Cache value that was set.

Cache event stale

Signals that a cache store entry is now stale (often due to a mutation) and should probably be reloaded. The event name starts with the cache key of the stale entry, followed by /stale.

Type: CustomEvent


class Loading

Loading store.

Examples

Ways to import.

import { Loading } from 'graphql-react';
import Loading from 'graphql-react/public/Loading.js';

Ways to require.

const { Loading } = require('graphql-react');
const Loading = require('graphql-react/public/Loading.js');

Construct a new instance.

const loading = new Loading();

Loading instance property store

Loading store, keyed by cache key. Multiple loading cache values for the same key are set in the order they started.

Type: object<CacheKey, Set<LoadingCacheValue>>

Loading event end

Signals the end of loading a cache value; either the loading finished and the cache value was set, the loading was aborted, or there was an error. The event name starts with the cache key, followed by /end.

Type: CustomEvent

Property Type Description
detail object Event detail.
detail.loadingCacheValue LoadingCacheValue Loading cache value that ended.

Loading event start

Signals the start of loading a cache value. The event name starts with the cache key, followed by /start.

Type: CustomEvent

Property Type Description
detail object Event detail.
detail.loadingCacheValue LoadingCacheValue Loading cache value that started.

class LoadingCacheValue

Controls a loading cache value.

Parameter Type Description
loading Loading Loading to update.
cache Cache Cache to update.
cacheKey CacheKey Cache key.
loadingResult Promise<CacheValue> Resolves the loading result (including any loading errors) to be set as the cache value if loading isn’t aborted. Shouldn’t reject.
abortController AbortController Aborts this loading and skips setting the loading result as the cache value. Has no affect after loading ends.

Fires

Examples

Ways to import.

import { LoadingCacheValue } from 'graphql-react';
import LoadingCacheValue from 'graphql-react/public/LoadingCacheValue.js';

Ways to require.

const { LoadingCacheValue } = require('graphql-react');
const LoadingCacheValue = require('graphql-react/public/LoadingCacheValue.js');

LoadingCacheValue instance property abortController

Aborts this loading and skips setting the loading result as the cache value. Has no affect after loading ends.

Type: AbortController

LoadingCacheValue instance property promise

Resolves the loading result, after the cache value has been set if the loading wasn’t aborted. Shouldn’t reject.

Type: Promise<*>

LoadingCacheValue instance property timeStamp

When this loading started.

Type: HighResTimeStamp


function cacheDelete

Deletes cache entries. Useful after a user logs out.

Parameter Type Description
cache Cache Cache to update.
cacheKeyMatcher CacheKeyMatcher? Matches cache keys to delete. By default all are matched.

Fires

Examples

Ways to import.

import { cacheDelete } from 'graphql-react';
import cacheDelete from 'graphql-react/public/cacheDelete.js';

Ways to require.

const { cacheDelete } = require('graphql-react');
const cacheDelete = require('graphql-react/public/cacheDelete.js');

function cacheEntryDelete

Deletes a cache entry.

Parameter Type Description
cache Cache Cache to update.
cacheKey CacheKey Cache key.

Fires

Examples

Ways to import.

import { cacheEntryDelete } from 'graphql-react';
import cacheEntryDelete from 'graphql-react/public/cacheEntryDelete.js';

Ways to require.

const { cacheEntryDelete } = require('graphql-react');
const cacheEntryDelete = require('graphql-react/public/cacheEntryDelete.js');

function cacheEntryPrune

Prunes a cache entry, if no prune event listener cancels the cache entry deletion via event.preventDefault().

Parameter Type Description
cache Cache Cache to update.
cacheKey CacheKey Cache key.

Fires

Examples

Ways to import.

import { cacheEntryPrune } from 'graphql-react';
import cacheEntryPrune from 'graphql-react/public/cacheEntryPrune.js';

Ways to require.

const { cacheEntryPrune } = require('graphql-react');
const cacheEntryPrune = require('graphql-react/public/cacheEntryPrune.js');

function cacheEntrySet

Sets a cache entry.

Parameter Type Description
cache Cache Cache to update.
cacheKey CacheKey Cache key.
cacheValue CacheValue Cache value.

Fires

Examples

Ways to import.

import { cacheEntrySet } from 'graphql-react';
import cacheEntrySet from 'graphql-react/public/cacheEntrySet.js';

Ways to require.

const { cacheEntrySet } = require('graphql-react');
const cacheEntrySet = require('graphql-react/public/cacheEntrySet.js');

function cacheEntryStale

Stales a cache entry, signalling it should probably be reloaded.

Parameter Type Description
cache Cache Cache to update.
cacheKey CacheKey Cache key.

Fires

Examples

Ways to import.

import { cacheEntryStale } from 'graphql-react';
import cacheEntryStale from 'graphql-react/public/cacheEntryStale.js';

Ways to require.

const { cacheEntryStale } = require('graphql-react');
const cacheEntryStale = require('graphql-react/public/cacheEntryStale.js');

function cachePrune

Prunes cache entries. Useful after a mutation.

Parameter Type Description
cache Cache Cache to update.
cacheKeyMatcher CacheKeyMatcher? Matches cache keys to prune. By default all are matched.

Fires

Examples

Ways to import.

import { cachePrune } from 'graphql-react';
import cachePrune from 'graphql-react/public/cachePrune.js';

Ways to require.

const { cachePrune } = require('graphql-react');
const cachePrune = require('graphql-react/public/cachePrune.js');

function cacheStale

Stales cache entries. Useful after a mutation.

Parameter Type Description
cache Cache Cache to update.
cacheKeyMatcher CacheKeyMatcher? Matches cache keys to stale. By default all are matched.

Fires

Examples

Ways to import.

import { cacheStale } from 'graphql-react';
import cacheStale from 'graphql-react/public/cacheStale.js';

Ways to require.

const { cacheStale } = require('graphql-react');
const cacheStale = require('graphql-react/public/cacheStale.js');

function fetchGraphQL

Fetches a GraphQL operation, always resolving a GraphQL result suitable for use as a cache value, even if there are errors. Loading errors are added to the GraphQL result errors property, and have an extensions property containing client: true, along with code and sometimes error-specific properties:

Error code Reasons Error specific properties
FETCH_ERROR Fetch error, e.g. the fetch global isn’t defined, or the network is offline. fetchErrorMessage (string).
RESPONSE_HTTP_STATUS Response HTTP status code is in the error range. statusCode (number), statusText (string).
RESPONSE_JSON_PARSE_ERROR Response JSON parse error. jsonParseErrorMessage (string).
RESPONSE_MALFORMED Response JSON isn’t an object, is missing an errors or data property, the errors property isn’t an array, or the data property isn’t an object or null.
Parameter Type Description
fetchUri string Fetch URI for the GraphQL API.
fetchOptions FetchOptions Fetch options.

Returns: Promise<GraphQLResult> — Resolves a result suitable for use as a cache value. Shouldn’t reject.

Examples

Ways to import.

import { fetchGraphQL } from 'graphql-react';
import fetchGraphQL from 'graphql-react/public/fetchGraphQL.js';

Ways to require.

const { fetchGraphQL } = require('graphql-react');
const fetchGraphQL = require('graphql-react/public/fetchGraphQL.js');

function fetchOptionsGraphQL

Creates default fetch options for a GraphQL operation. If the GraphQL operation contains files to upload, the options will be for a GraphQL multipart request, otherwise they will be for a regular GraphQL POST request.

This utility exists for user convenience and isn’t used directly by the graphql-react API. If there is no chance the GraphQL operation contains files, avoid using this utility for a smaller bundle size.

Parameter Type Description
operation GraphQLOperation GraphQL operation.

Returns: FetchOptionsfetch options.

Examples

Ways to import.

import { fetchOptionsGraphQL } from 'graphql-react';
import fetchOptionsGraphQL from 'graphql-react/public/fetchOptionsGraphQL.js';

Ways to require.

const { fetchOptionsGraphQL } = require('graphql-react');
const fetchOptionsGraphQL = require('graphql-react/public/fetchOptionsGraphQL.js');

function Provider

A React component to provide all the React context required to enable the entire graphql-react API:

Parameter Type Description
props object Component props.
props.cache Cache Cache instance.
props.children ReactNode? React children.

Returns: ReactNode — React virtual DOM node.

Examples

Ways to import.

import { Provider } from 'graphql-react';
import Provider from 'graphql-react/public/Provider.js';

Ways to require.

const { Provider } = require('graphql-react');
const Provider = require('graphql-react/public/Provider.js');

Provide a Cache instance for an app.

import { Cache, Provider } from 'graphql-react';
import React from 'react';

const cache = new Cache();

const App = ({ children }) => <Provider cache={cache}>{children}</Provider>;

function useAutoAbortLoad

A React hook to create a memoized loader from another, that automatically aborts previous loading that started via this hook when new loading starts via this hook, the hook arguments change, or the component unmounts.

Parameter Type Description
load Loader Memoized function that starts the loading.

Returns: Loader — Memoized function that starts the loading.

Examples

Ways to import.

import { useAutoAbortLoad } from 'graphql-react';
import useAutoAbortLoad from 'graphql-react/public/useAutoAbortLoad.js';

Ways to require.

const { useAutoAbortLoad } = require('graphql-react');
const useAutoAbortLoad = require('graphql-react/public/useAutoAbortLoad.js');

function useAutoLoad

A React hook to prevent a cache entry from being pruned while the component is mounted and automatically keep it loaded. Previous loading that started via this hook aborts when new loading starts via this hook, the hook arguments change, or the component unmounts.

Parameter Type Description
cacheKey CacheKey Cache key.
load Loader Memoized function that starts the loading.

Returns: Loader — Memoized loader created from the load argument, that automatically aborts the last loading when the memoized function changes or the component unmounts.

See

Examples

Ways to import.

import { useAutoLoad } from 'graphql-react';
import useAutoLoad from 'graphql-react/public/useAutoLoad.js';

Ways to require.

const { useAutoLoad } = require('graphql-react');
const useAutoLoad = require('graphql-react/public/useAutoLoad.js');

function useCache

A React hook to get the cache context.

Returns: Cache — The cache.

Examples

Ways to import.

import { useCache } from 'graphql-react';
import useCache from 'graphql-react/public/useCache.js';

Ways to require.

const { useCache } = require('graphql-react');
const useCache = require('graphql-react/public/useCache.js');

function useCacheEntry

A React hook to get a cache value using its cache key.

Parameter Type Description
cacheKey CacheKey Cache key.

Returns: CacheValue — Cache value, if present.

Examples

Ways to import.

import { useCacheEntry } from 'graphql-react';
import useCacheEntry from 'graphql-react/public/useCacheEntry.js';

Ways to require.

const { useCacheEntry } = require('graphql-react');
const useCacheEntry = require('graphql-react/public/useCacheEntry.js');

function useCacheEntryPrunePrevention

A React hook to prevent a cache entry from being pruned, by canceling the cache entry deletion for prune events with event.preventDefault().

Parameter Type Description
cacheKey CacheKey Cache key.

Examples

Ways to import.

import { useCacheEntryPrunePrevention } from 'graphql-react';
import useCacheEntryPrunePrevention from 'graphql-react/public/useCacheEntryPrunePrevention.js';

Ways to require.

const { useCacheEntryPrunePrevention } = require('graphql-react');
const useCacheEntryPrunePrevention = require('graphql-react/public/useCacheEntryPrunePrevention.js');

function useLoadGraphQL

A React hook to get a function for loading a GraphQL operation.

Returns: LoadGraphQL — Loads a GraphQL operation.

Examples

Ways to import.

import { useLoadGraphQL } from 'graphql-react';
import useLoadGraphQL from 'graphql-react/public/useLoadGraphQL.js';

Ways to require.

const { useLoadGraphQL } = require('graphql-react');
const useLoadGraphQL = require('graphql-react/public/useLoadGraphQL.js');

function useLoading

A React hook to get the loading context.

Returns: Loading — Loading.

Examples

Ways to import.

import { useLoading } from 'graphql-react';
import useLoading from 'graphql-react/public/useLoading.js';

Ways to require.

const { useLoading } = require('graphql-react');
const useLoading = require('graphql-react/public/useLoading.js');

function useLoadingEntry

A React hook to get the loading cache values for a given cache key.

Parameter Type Description
cacheKey CacheKey Cache key.

Returns: Set<LoadingCacheValue> | undefined — Loading cache values, if present.

Examples

Ways to import.

import { useLoadingEntry } from 'graphql-react';
import useLoadingEntry from 'graphql-react/public/useLoadingEntry.js';

Ways to require.

const { useLoadingEntry } = require('graphql-react');
const useLoadingEntry = require('graphql-react/public/useLoadingEntry.js');

function useLoadOnDelete

A React hook to load a cache entry after it’s deleted, if there isn’t loading for the cache key that started after.

Parameter Type Description
cacheKey CacheKey Cache key.
load Loader Memoized function that starts the loading.

Examples

Ways to import.

import { useLoadOnDelete } from 'graphql-react';
import useLoadOnDelete from 'graphql-react/public/useLoadOnDelete.js';

Ways to require.

const { useLoadOnDelete } = require('graphql-react');
const useLoadOnDelete = require('graphql-react/public/useLoadOnDelete.js');

function useLoadOnMount

A React hook to automatically load a cache entry after the component mounts or the cache context or any of the arguments change, except during the hydration time if the hydration time stamp context is populated and the cache entry is already populated.

Parameter Type Description
cacheKey CacheKey Cache key.
load Loader Memoized function that starts the loading.

Examples

Ways to import.

import { useLoadOnMount } from 'graphql-react';
import useLoadOnMount from 'graphql-react/public/useLoadOnMount.js';

Ways to require.

const { useLoadOnMount } = require('graphql-react');
const useLoadOnMount = require('graphql-react/public/useLoadOnMount.js');

function useLoadOnStale

A React hook to load a cache entry after becomes stale, if there isn’t loading for the cache key that started after.

Parameter Type Description
cacheKey CacheKey Cache key.
load Loader Memoized function that starts the loading.

Examples

Ways to import.

import { useLoadOnStale } from 'graphql-react';
import useLoadOnStale from 'graphql-react/public/useLoadOnStale.js';

Ways to require.

const { useLoadOnStale } = require('graphql-react');
const useLoadOnStale = require('graphql-react/public/useLoadOnStale.js');

function useWaterfallLoad

A React hook to load a cache entry if the waterfall render context is populated, i.e. when waterfall rendering for either a server side render or to preload components in a browser environment.

Parameter Type Description
cacheKey CacheKey Cache key.
load Loader Memoized function that starts the loading.

Returns: boolean — Did loading start. If so, it’s efficient for the component to return null since this render will be discarded anyway for a re-render onces the loading ends.

See

Examples

Ways to import.

import { useWaterfallLoad } from 'graphql-react';
import useWaterfallLoad from 'graphql-react/public/useWaterfallLoad.js';

Ways to require.

const { useWaterfallLoad } = require('graphql-react');
const useWaterfallLoad = require('graphql-react/public/useWaterfallLoad.js');

member CacheContext

React context for a Cache instance.

Type: object

Property Type Description
Provider Function React context provider component.
Consumer Function React context consumer component.

Examples

Ways to import.

import { CacheContext } from 'graphql-react';
import CacheContext from 'graphql-react/public/CacheContext.js';

Ways to require.

const { CacheContext } = require('graphql-react');
const CacheContext = require('graphql-react/public/CacheContext.js');

member HydrationTimeStampContext

React context for the client side hydration time stamp.

Type: object

Property Type Description
Provider Function React context provider component.
Consumer Function React context consumer component.

Examples

Ways to import.

import { HydrationTimeStampContext } from 'graphql-react';
import HydrationTimeStampContext from 'graphql-react/public/HydrationTimeStampContext.js';

Ways to require.

const { HydrationTimeStampContext } = require('graphql-react');
const HydrationTimeStampContext = require('graphql-react/public/HydrationTimeStampContext.js');

member LoadingContext

React context for a Loading instance.

Type: object

Property Type Description
Provider Function React context provider component.
Consumer Function React context consumer component.

Examples

Ways to import.

import { LoadingContext } from 'graphql-react';
import LoadingContext from 'graphql-react/public/LoadingContext.js';

Ways to require.

const { LoadingContext } = require('graphql-react');
const LoadingContext = require('graphql-react/public/LoadingContext.js');

constant HYDRATION_TIME_MS

Number of milliseconds after the first client render that’s considered the hydration time; during which the useAutoLoad React hook won’t load if the cache entry is already populated.

Type: number

Examples

Ways to import.

import { HYDRATION_TIME_MS } from 'graphql-react';
import HYDRATION_TIME_MS from 'graphql-react/public/HYDRATION_TIME_MS.js';

Ways to require.

const { HYDRATION_TIME_MS } = require('graphql-react');
const HYDRATION_TIME_MS = require('graphql-react/public/HYDRATION_TIME_MS.js');

type CacheKey

A unique key to access a cache value.

Type: string


type CacheKeyMatcher

Matches a cache key against a custom condition.

Type: Function

Parameter Type Description
cacheKey CacheKey Cache key.

Returns: boolean — Does the cache key match the custom condition.


type CacheValue

A cache value. If server side rendering, it should be JSON serializable for client hydration. It should contain information about any errors that occurred during loading so they can be rendered, and if server side rendering, be hydrated on the client.

Type: *


type FetchOptions

fetch options, called init in official specs.

Type: object

See


type GraphQLOperation

A GraphQL operation. Additional properties may be used; all are sent to the GraphQL server.

Type: object

Property Type Description
query string GraphQL queries or mutations.
variables object? Variables used in the query.

type GraphQLResult

A GraphQL result.

Type: object

Property Type Description
data object? GraphQL response data.
errors Array<GraphQLResultError>? GraphQL response errors from the server, along with any loading errors added on the client.

See


type GraphQLResultError

A GraphQL result error; either created by the GraphQL server, or by whatever loaded the GraphQL on the client (e.g. fetchGraphQL).

Type: object

Property Type Description
message object Error message.
locations Array<{line: number, column: number}>? GraphQL query locations related to the error.
path Array? GraphQL result data field path related to the error.
extensions object? Custom error data. If the error was created on the client and not the GraphQL server, this property should be present and contain at least client: true, although code and error specific properties may be present.

See


type HighResTimeStamp

Milliseconds since the performance time origin (when the current JavaScript environment started running).

Type: number

See


type Loader

Starts loading a cache value.

Type: Function

Returns: LoadingCacheValue — The loading cache value.


type LoadGraphQL

Loads a GraphQL operation, using the GraphQL fetcher.

Type: Loader

Parameter Type Description
cacheKey CacheKey Cache key to store the loading result under.
fetchUri string fetch URI.
fetchOptions FetchOptions fetch options.

Returns: LoadingCacheValue — The loading cache value.


type ReactNode

A React virtual DOM node; anything that can be rendered.

Type: undefined | null | boolean | number | string | React.Element | Array<ReactNode>

  • 声明: 转载请注明出处 1.依赖引入 import gql from 'graphql-tag'; import { graphql } from 'react-apollo'; import view from '...'; //导入视图界面 2. graphql查询语句 //使用$声明的变量进行条件查询,在变量类型后加 ! 符号可决定该条件为必须变量 //如果直接使用数值查询,就不需要变量,直

  • 前段时间,分享了一篇GraphQL & Relay 初探,主要介绍了 GraphQL 的设计思想和 Relay 的基本应用。 目前,笔者在实际项目中应用 GraphQL+Relay 已经有段时间了,并发布了一个正式版本。整个过程中,踩了不少坑,也摸索出了一些经验,特此做一下总结分享。 架构&角色分工 对于架构设计与角色分工,一定程度上,依赖于团队人员的配置。由于我们团队主要由后端研发组成,前端人数

  • Node使用Graphql 我们在实际的开发过程中同城会出现这种情况,单个后台对应多个前端,而且前端需要的数据格式并不一样,这就需要后端进行判断或者使用中台进行数据处理 中台的搭建有两种方法 使用axios.all方法获取数据进行处理。 exports.get = ({url, params={}}) => { return axios({ url, params })

  • 官网: http://graphql.cn/learn/ 快速了解: https://www.howtographql.com/ GraphQL With Golang and PostgreSQL: http://alexandrutopliceanu.ro/post/graphql-with-go-and-postgresql/ 从最后一篇的demo可以看出来,需要根据应用场景的不同,在究竟是

  • 声明: 转载请注明出处 1. 具体细节可参考我博客的另一篇文章 2.mutation的graphql语句定义 const recNewJobSql = gql ` mutation addJobsV1( $jobTitle:String!,$jobDepart:String!, $jobNum:String!,$jobFit:Int!, ){ addJobsV1( jobNu

  • 作者:poetry 原文地址:https://mp.weixin.qq.com/s/UyjYakPcSl-Z1A49o0ohCQ 前言 过去几年中,GraphQL 已经成为一种非常流行的 API 规范,该规范专注于使客户端(无论是客户端、前端还是第三方)的数据获取更加容易。 在传统的基于 REST 的 API 方法中,客户端发出请求,而服务端决定响应。 但是在 GraphQL 中,客户端可以精确地

  • 参考  ES7 React/Redux/GraphQL/React-Native snippets - Visual Studio Marketplace 1.  下载 ES7 React/Redux/GraphQL/React-Native snippets 2.  再.jsx 或 .js 文件中填入前缀  函数式组件的前缀  rfce  class组件的前缀  rcc

 相关资料
  • 快速开始 GraphQL 是一种用于 API 的查询语言。这是 GraphQL 和 REST 之间一个很好的比较 (译者注: GraphQL 替代 REST 是必然趋势)。在这组文章中, 我们不会解释什幺是 GraphQL, 而是演示如何使用 @nestjs/GraphQL 模块。 GraphQLModule 只不过是 Apollo 服务器的包装器。我们没有造轮子, 而是提供一个现成的模块, 这让

  • GraphQL 既是一种用于 API 的查询语言也是一个满足你数据查询的运行时。 GraphQL 对你的 API 中的数据提供了一套易于理解的完整描述,使得客户端能够准确地获得它需要的数据,而且没有任何冗余,也让 API 更容易地随着时间推移而演进,还能用于构建强大的开发者工具。 向你的 API 发出一个 GraphQL 请求就能准确获得你想要的数据,不多不少。 GraphQL 查询总是返回可预测

  • Fullstack GraphQL Boilerplates for React & Node.js Bootstrap your fullstack GraphQL app within seconds GraphQL boilerplates provide the perfect foundation for your GraphQL server, no matter if you're

  • Hacker News Clone React/GraphQL This project is a clone of hacker news rewritten with universal JavaScript, using React and GraphQL. It is intended to be an example or boilerplate to help you structur

  • 我按照Apollo的文档在客户端和服务器上设置GraphQL订阅,虽然我已经完成了90%,但我不知道如何设置订阅通道以及如何将突变连接到这些通道,以便每当突变发生时,服务器都会将新数据推送到客户端。(对于内容,我正在制作一个Reddit克隆,人们可以在其中发布主题,其他人可以对其发表评论。所以当你看到“Topics”或“TopicList”时,把它们想象成帖子。) 到目前为止,我已经成功地为订阅设

  • Graphql editor 是一款 Graphql 的可视化编辑器和 IDE,帮助用户更容易理解 GraphQL 模式,通过使用可视化块系统创建模式。GraphQL Editor 将把它们转化为代码。通过 GraphQL Editor,用户可以在不写任何代码的情况下创建可视化的图表,或者以一种很好的方式呈现其模式。 GraphQL View Code Editor View Hierarchy View