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

@shopify/react-graphql

Package Overview
Dependencies
Maintainers
19
Versions
263
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@shopify/react-graphql - npm Package Compare versions

Comparing version 0.0.0-snapshot-20221129224804 to 0.0.0-snapshot-20221201003551

14

build/cjs/ApolloProvider.js

@@ -6,3 +6,3 @@ 'use strict';

var React = require('react');
var reactCommon = require('@apollo/react-common');
var client = require('@apollo/client');
var ApolloContext = require('./ApolloContext.js');

@@ -15,11 +15,11 @@

function ApolloProvider({
client,
client: client$1,
children
}) {
const providerValue = React__default["default"].useMemo(() => ({
client,
operations: client.__operations_cache__
}), [client]);
return /*#__PURE__*/React__default["default"].createElement(reactCommon.ApolloProvider, {
client: client
client: client$1,
operations: client$1.__operations_cache__
}), [client$1]);
return /*#__PURE__*/React__default["default"].createElement(client.ApolloProvider, {
client: client$1
}, /*#__PURE__*/React__default["default"].createElement(ApolloContext.ApolloContext.Provider, {

@@ -26,0 +26,0 @@ value: providerValue

@@ -6,3 +6,3 @@ 'use strict';

var React = require('react');
var apolloClient$1 = require('apollo-client');
var client = require('@apollo/client');
var isEqual = require('fast-deep-equal');

@@ -36,9 +36,9 @@ var reactEffect = require('@shopify/react-effect');

const variables = options.variables || {};
const client = apolloClient["default"](overrideClient);
const client$1 = apolloClient["default"](overrideClient);
if (typeof window === 'undefined') {
if (skip) {
return createDefaultResult(client, variables);
return createDefaultResult(client$1, variables);
} else if (!ssr || fetchPolicy === 'no-cache') {
return createDefaultResult(client, variables, undefined, true);
return createDefaultResult(client$1, variables, undefined, true);
}

@@ -71,4 +71,4 @@ }

return client.watchQuery(watchQueryOptions);
}, [client, skip, watchQueryOptions]);
return client$1.watchQuery(watchQueryOptions);
}, [client$1, skip, watchQueryOptions]);
reactEffect.useServerEffect(() => {

@@ -82,4 +82,4 @@ if (queryObservable == null) {

});
const defaultResult = React.useMemo(() => createDefaultResult(client, variables, queryObservable), // eslint-disable-next-line react-hooks/exhaustive-deps
[queryObservable, client, serializedVariables]);
const defaultResult = React.useMemo(() => createDefaultResult(client$1, variables, queryObservable), // eslint-disable-next-line react-hooks/exhaustive-deps
[queryObservable, client$1, serializedVariables]);
const [responseId, setResponseId] = React.useState(0);

@@ -101,4 +101,4 @@ React.useEffect(() => {

function invalidateErrorResult(error) {
const lastError = queryObservable.getLastError();
const lastResult = queryObservable.getLastResult();
// @ts-expect-error access last
const lastResult = queryObservable === null || queryObservable === void 0 ? void 0 : queryObservable.last;
unsubscribe();

@@ -110,6 +110,4 @@

} finally {
Object.assign(queryObservable || {}, {
lastError,
lastResult
});
// @ts-expect-error override last
queryObservable.last = lastResult;
}

@@ -130,4 +128,10 @@

function subscribe() {
subscription = queryObservable.subscribe(() => {
previousError = undefined;
subscription = queryObservable.subscribe(status => {
previousError = undefined; // apollo 3 calls this when 2 didn't prevent
// the extra render
if (currentResult.loading === status.loading && currentResult.networkStatus === status.networkStatus && status.partial) {
return;
}
invalidateCurrentResult();

@@ -148,3 +152,3 @@ }, error => {

subscribe();
return unsubscribe;
return unsubscribe; // eslint-disable-next-line react-hooks/exhaustive-deps
}, [skip, queryObservable]);

@@ -187,3 +191,3 @@ const previousData = React.useRef(undefined);

data,
error: hasError ? new apolloClient$1.ApolloError({
error: hasError ? new client.ApolloError({
graphQLErrors: result.errors

@@ -190,0 +194,0 @@ }) : result.error,

@@ -6,3 +6,3 @@ 'use strict';

var async = require('@shopify/async');
var apolloClient = require('apollo-client');
var client = require('@apollo/client');
var Query = require('./Query.js');

@@ -12,3 +12,3 @@ var Prefetch = require('./Prefetch.js');

var links = require('./links.js');
var apolloClient$1 = require('./hooks/apollo-client.js');
var apolloClient = require('./hooks/apollo-client.js');
var query$1 = require('./hooks/query.js');

@@ -28,7 +28,7 @@ var mutation = require('./hooks/mutation.js');

enumerable: true,
get: function () { return apolloClient.ApolloError; }
get: function () { return client.ApolloError; }
});
Object.defineProperty(exports, 'NetworkStatus', {
enumerable: true,
get: function () { return apolloClient.NetworkStatus; }
get: function () { return client.NetworkStatus; }
});

@@ -40,3 +40,3 @@ exports.Query = Query.Query;

exports.createSsrExtractableLink = links.createSsrExtractableLink;
exports.useApolloClient = apolloClient$1["default"];
exports.useApolloClient = apolloClient["default"];
exports.useQuery = query$1["default"];

@@ -43,0 +43,0 @@ exports.useMutation = mutation["default"];

@@ -5,3 +5,3 @@ 'use strict';

var apolloLink = require('apollo-link');
var client = require('@apollo/client');

@@ -11,3 +11,3 @@ function createSsrExtractableLink() {

}
class SsrExtractableLink extends apolloLink.ApolloLink {
class SsrExtractableLink extends client.ApolloLink {
constructor(...args) {

@@ -14,0 +14,0 @@ super(...args);

import React from 'react';
import { ApolloClient } from 'apollo-client';
import { ApolloClient } from '@apollo/client';
import { DocumentNode } from 'graphql-typed';

@@ -4,0 +4,0 @@ export interface ApolloContextValue<CacheShape = any> {

import React from 'react';
import { ApolloClient } from 'apollo-client';
import { ApolloClient } from '@apollo/client';
export interface Props<CacheShape> {

@@ -4,0 +4,0 @@ readonly client: ApolloClient<CacheShape>;

import { AsyncQueryComponentType } from '../types';
import { Options } from './query';
export declare function createAsyncQueryComponent<Data extends {}, Variables extends {}, DeepPartial extends {}>(options: Options<Data, Variables, DeepPartial>): AsyncQueryComponentType<Data, Variables, DeepPartial>;
export declare function createAsyncQueryComponent<Data, Variables, DeepPartial>(options: Options<Data, Variables, DeepPartial>): AsyncQueryComponentType<Data, Variables, DeepPartial>;
//# sourceMappingURL=component.d.ts.map

@@ -6,3 +6,3 @@ import { DocumentNode } from 'graphql-typed';

}
export declare function createAsyncQuery<Data extends {}, Variables extends {}, DeepPartial extends {}>({ id, load, }: Options<Data, Variables, DeepPartial>): AsyncDocumentNode<Data, Variables, DeepPartial>;
export declare function createAsyncQuery<Data, Variables, DeepPartial>({ id, load, }: Options<Data, Variables, DeepPartial>): AsyncDocumentNode<Data, Variables, DeepPartial>;
//# sourceMappingURL=query.d.ts.map

@@ -1,3 +0,3 @@

import { ApolloClient } from 'apollo-client';
import { ApolloClient } from '@apollo/client';
export default function useApolloClient<CacheShape>(overrideClient?: ApolloClient<CacheShape>): ApolloClient<CacheShape>;
//# sourceMappingURL=apollo-client.d.ts.map
import { DocumentNode } from 'graphql-typed';
import { WatchQueryOptions } from 'apollo-client';
import { WatchQueryOptions } from '@apollo/client';
export declare function useBackgroundQuery(load: () => Promise<DocumentNode | null | Error>, options?: Omit<WatchQueryOptions, 'query'>): () => Promise<void>;
//# sourceMappingURL=background-query.d.ts.map

@@ -1,5 +0,5 @@

import { OperationVariables } from 'apollo-client';
import { OperationVariables } from '@apollo/client';
import { DocumentNode } from 'graphql-typed';
import { AsyncDocumentNode } from '../types';
export default function useGraphQLDocument<Data extends {} = any, Variables extends OperationVariables = OperationVariables, DeepPartial extends {} = {}>(documentOrAsyncDocument: DocumentNode<Data, Variables> | AsyncDocumentNode<Data, Variables, DeepPartial>): DocumentNode<Data, Variables> | null;
export default function useGraphQLDocument<Data = any, Variables = OperationVariables, DeepPartial = {}>(documentOrAsyncDocument: DocumentNode<Data, Variables> | AsyncDocumentNode<Data, Variables, DeepPartial>): DocumentNode<Data, Variables> | null;
//# sourceMappingURL=graphql-document.d.ts.map

@@ -1,2 +0,2 @@

import { OperationVariables } from 'apollo-client';
import { OperationVariables } from '@apollo/client';
import { DocumentNode } from 'graphql-typed';

@@ -3,0 +3,0 @@ import { NoInfer } from '@shopify/useful-types';

@@ -1,2 +0,2 @@

import { OperationVariables } from 'apollo-client';
import { OperationVariables } from '@apollo/client';
import { DocumentNode } from 'graphql-typed';

@@ -6,3 +6,3 @@ import { IfAllNullableKeys, NoInfer } from '@shopify/useful-types';

import { QueryHookOptions, QueryHookResult } from './types';
export default function useQuery<Data extends {} = any, Variables extends OperationVariables = OperationVariables, DeepPartial extends {} = {}>(queryOrAsyncQuery: DocumentNode<Data, Variables, DeepPartial> | AsyncDocumentNode<Data, Variables, DeepPartial>, ...optionsPart: IfAllNullableKeys<Variables, [
export default function useQuery<Data = any, Variables = OperationVariables, DeepPartial = {}>(queryOrAsyncQuery: DocumentNode<Data, Variables, DeepPartial> | AsyncDocumentNode<Data, Variables, DeepPartial>, ...optionsPart: IfAllNullableKeys<Variables, [
QueryHookOptions<Data, NoInfer<Variables>>?

@@ -9,0 +9,0 @@ ], [

@@ -1,21 +0,20 @@

import { ApolloClient, MutationOptions as ClientMutationOptions } from 'apollo-client';
import { QueryResult, ExecutionResult, OperationVariables } from '@apollo/react-common';
import { QueryOptions, MutationOptions } from '@apollo/react-hooks';
import { ApolloClient, MutationOptions as ClientMutationOptions, QueryResult, OperationVariables, MutationOptions, FetchResult } from '@apollo/client';
import { QueryComponentOptions } from '@apollo/client/react/components';
import { IfAllNullableKeys } from '@shopify/useful-types';
import { VariableOptions } from '../types';
export type QueryHookOptions<Data = any, Variables = OperationVariables> = Omit<QueryOptions<Data, Variables>, 'query' | 'partialRefetch' | 'children' | 'variables'> & VariableOptions<Variables> & {
export declare type QueryHookOptions<Data = any, Variables = OperationVariables> = Omit<QueryComponentOptions<Data, Variables>, 'query' | 'partialRefetch' | 'children' | 'variables'> & VariableOptions<Variables> & {
skip?: boolean;
};
export interface QueryHookResult<Data, Variables> extends Omit<QueryResult<Data, Variables>, 'networkStatus' | 'variables'> {
export interface QueryHookResult<Data, Variables> extends Omit<QueryResult<Data, Variables>, 'networkStatus' | 'variables' | 'reobserve' | 'observable'> {
networkStatus: QueryResult<Data, Variables>['networkStatus'] | undefined;
variables: QueryResult<Data, Variables>['variables'] | undefined;
}
export type MutationHookOptions<Data = any, Variables = OperationVariables> = Omit<MutationOptions<Data, Variables>, 'variables' | 'mutation' | 'fetchPolicy'> & VariableOptions<Variables> & Pick<ClientMutationOptions<Data, Variables>, 'fetchPolicy'> & {
export declare type MutationHookOptions<Data = any, Variables = OperationVariables> = Omit<MutationOptions<Data, Variables>, 'variables' | 'mutation' | 'fetchPolicy'> & VariableOptions<Variables> & Pick<ClientMutationOptions<Data, Variables>, 'fetchPolicy'> & {
client?: ApolloClient<object>;
};
export type MutationHookResult<Data, Variables> = (...optionsPart: IfAllNullableKeys<Variables, [
export declare type MutationHookResult<Data, Variables> = (...optionsPart: IfAllNullableKeys<Variables, [
MutationHookOptions<Data, Variables>?
], [
MutationHookOptions<Data, Variables>
]>) => Promise<ExecutionResult<Data>>;
]>) => Promise<FetchResult<Data>>;
//# sourceMappingURL=types.d.ts.map
export { DeferTiming } from '@shopify/async';
export { ApolloError, NetworkStatus } from 'apollo-client';
export { ApolloError, NetworkStatus } from '@apollo/client';
export { Query } from './Query';

@@ -4,0 +4,0 @@ export { Prefetch } from './Prefetch';

@@ -1,2 +0,2 @@

import { ApolloLink, Operation, NextLink } from 'apollo-link';
import { ApolloLink, Operation, NextLink } from '@apollo/client';
export declare function createSsrExtractableLink(): SsrExtractableLink;

@@ -6,6 +6,4 @@ export declare class SsrExtractableLink extends ApolloLink {

resolveAll<T>(then: () => T): Promise<T> | T;
request(operation: Operation, nextLink?: NextLink): import("apollo-link").Observable<import("apollo-link").FetchResult<{
[key: string]: any;
}, Record<string, any>, Record<string, any>>>;
request(operation: Operation, nextLink?: NextLink): import("zen-observable-ts").Observable<import("@apollo/client").FetchResult<Record<string, any>, Record<string, any>, Record<string, any>>>;
}
//# sourceMappingURL=links.d.ts.map
/// <reference types="react" />
import { QueryProps } from './types';
export type Props<T> = Pick<QueryProps<T>, 'query' | 'variables' | 'onError' | 'onCompleted' | 'pollInterval'> & {
export declare type Props<T> = Pick<QueryProps<T>, 'query' | 'variables' | 'onError' | 'onCompleted' | 'pollInterval'> & {
ignoreCache?: boolean;
};
export declare function Prefetch<T extends {}>({ ignoreCache, ...props }: Props<T>): JSX.Element;
export declare function Prefetch<T>({ ignoreCache, ...props }: Props<T>): JSX.Element;
//# sourceMappingURL=Prefetch.d.ts.map
/// <reference types="react" />
import { OperationVariables } from 'apollo-client';
import { OperationVariables } from '@apollo/client';
import { DocumentNode } from 'graphql-typed';

@@ -9,4 +9,4 @@ import { QueryHookResult, QueryHookOptions } from './hooks';

}
export declare function Query<Data extends {} = any, Variables extends OperationVariables = OperationVariables>({ children, query, ...options }: QueryComponentOptions<Data, Variables>): JSX.Element | null;
export declare function Query<Data = any, Variables = OperationVariables>({ children, query, ...options }: QueryComponentOptions<Data, Variables>): JSX.Element | null;
export {};
//# sourceMappingURL=Query.d.ts.map
import React from 'react';
import { DocumentNode, GraphQLOperation, GraphQLData, GraphQLVariables, GraphQLDeepPartial } from 'graphql-typed';
import { QueryResult } from '@apollo/react-common';
import { ErrorPolicy, OperationVariables, ApolloError, ApolloClient, WatchQueryFetchPolicy } from 'apollo-client';
import { QueryResult, ErrorPolicy, OperationVariables, ApolloError, ApolloClient, WatchQueryFetchPolicy } from '@apollo/client';
import { IfEmptyObject, IfAllNullableKeys } from '@shopify/useful-types';

@@ -9,3 +8,3 @@ import { AsyncComponentType, AsyncHookTarget } from '@shopify/react-async';

export type { GraphQLData, GraphQLVariables, GraphQLDeepPartial, GraphQLOperation, };
export type VariableOptions<Variables> = IfEmptyObject<Variables, {
export declare type VariableOptions<Variables> = IfEmptyObject<Variables, {
variables?: never;

@@ -17,3 +16,3 @@ }, IfAllNullableKeys<Variables, {

}>>;
export type QueryProps<Data = any, Variables = OperationVariables> = {
export declare type QueryProps<Data = any, Variables = OperationVariables> = {
children: (result: QueryResult<Data, Variables>) => React.ReactNode;

@@ -20,0 +19,0 @@ fetchPolicy?: WatchQueryFetchPolicy;

{
"name": "@shopify/react-graphql",
"version": "0.0.0-snapshot-20221129224804",
"version": "0.0.0-snapshot-20221201003551",
"license": "MIT",

@@ -27,13 +27,9 @@ "description": "Tools for creating type-safe and asynchronous GraphQL components for React",

"dependencies": {
"@apollo/react-common": ">=3.0.0 <4.0.0",
"@apollo/react-hooks": ">=3.0.0 <4.0.0",
"@apollo/client": "^3.5.8",
"@shopify/async": "^4.0.1",
"@shopify/react-async": "0.0.0-snapshot-20221129224804",
"@shopify/react-async": "^5.0.6",
"@shopify/react-effect": "^5.0.2",
"@shopify/react-hooks": "^3.0.2",
"@shopify/react-idle": "0.0.0-snapshot-20221129224804",
"@shopify/react-idle": "^3.0.3",
"@shopify/useful-types": "^5.1.1",
"apollo-cache-inmemory": ">=1.0.0 <2.0.0",
"apollo-client": ">=2.0.0 <3.0.0",
"apollo-link": ">=1.0.0 <2.0.0",
"graphql-typed": "^2.0.1",

@@ -43,3 +39,3 @@ "fast-deep-equal": "^3.1.3"

"devDependencies": {
"@shopify/react-testing": "0.0.0-snapshot-20221129224804"
"@shopify/react-testing": "^5.0.1"
},

@@ -46,0 +42,0 @@ "files": [

@@ -17,3 +17,3 @@ # `@shopify/react-graphql`

This library builds on top of [react-apollo](https://github.com/apollographql/react-apollo). It provides alternatives to many of Apollo’s APIs, including `useQuery` and `useMutation`, to provide seamless and thorough type checking for query components whose types are generated by [`graphql-typescript-definitions`](https://github.com/Shopify/quilt/tree/main/packages/graphql-typescript-definitions). Additionally, it provides techniques for creating asynchronously loaded GraphQL queries that seamlessly interoperate with [`@shopify/react-async`’s](../react-async) `usePreload`, `usePrefetch`, and `useKeepFresh` APIs.
This library builds on top of [@apollo/client](https://github.com/apollographql/apollo-client). It provides alternatives to many of Apollo’s APIs, including `useQuery` and `useMutation`, to provide seamless and thorough type checking for query components whose types are generated by [`graphql-typescript-definitions`](https://github.com/Shopify/quilt/tree/main/packages/graphql-typescript-definitions). Additionally, it provides techniques for creating asynchronously loaded GraphQL queries that seamlessly interoperate with [`@shopify/react-async`’s](../react-async) `usePreload`, `usePrefetch`, and `useKeepFresh` APIs.

@@ -26,3 +26,3 @@ ### Prerequisites

Before using the hooks and other utilities provided by this package, you must wrap your application in an `ApolloProvider`. This provider should be used instead of `react-apollo`'s [`ApolloProvider`](https://www.apollographql.com/docs/react/api/react-apollo#ApolloProvider), and it accepts the same props as that component.
Before using the hooks and other utilities provided by this package, you must wrap your application in an `ApolloProvider`. This provider should be used instead of `@apollo/client`'s [`ApolloProvider`](https://www.apollographql.com/docs/react/api/react/hooks/#the-apolloprovider-component), and it accepts the same props as that component.

@@ -33,3 +33,3 @@ ```tsx

import {ApolloClient} from 'apollo-client';
import {ApolloClient} from '@apollo/client';
import {ApolloProvider} from '@shopify/react-graphql';

@@ -170,3 +170,3 @@

import React from 'react';
import gql from 'graphql-tag';
import {gql} from '@apollo/client';
import {useApolloClient} from '@shopify/react-graphql';

@@ -307,3 +307,3 @@ import {Button} from '@shopify/polaris';

react-apollo’s `Query` component is great, but does not have any built-in understanding of the connection between a GraphQL operation (provided in the `query` prop) and the data types of the resulting query. This library re-exports a `Query` component with improved typings. It will automatically read from from the types embedded in the query by `graphql-typescript-definitions` and use these as appropriate for the rest of the `Query` component’s props.
`@apollo/client`’s `Query` component is great, but does not have any built-in understanding of the connection between a GraphQL operation (provided in the `query` prop) and the data types of the resulting query. This library re-exports a `Query` component with improved typings. It will automatically read from from the types embedded in the query by `graphql-typescript-definitions` and use these as appropriate for the rest of the `Query` component’s props.

@@ -310,0 +310,0 @@ ```tsx

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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