@graphiql/toolkit
Advanced tools
Comparing version 0.8.4 to 0.9.0-canary-38c2c299.0
# @graphiql/toolkit | ||
## 0.9.0-canary-38c2c299.0 | ||
### Minor Changes | ||
- [`7d6997a1`](https://github.com/graphql/graphiql/commit/7d6997a188e91af8138820d0d2508f871bbd22f0) Thanks [@acao](https://github.com/acao)! - _BREAKING CHANGE:_ drop commonjs exports in all libraries except for `graphiql` and `@graphiql/react` | ||
## 0.8.4 | ||
@@ -4,0 +10,0 @@ |
@@ -32,5 +32,5 @@ # `createGraphiQLFetcher` | ||
```ts | ||
```jsx | ||
import * as React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import { createRoot } from 'react-dom/client'; | ||
import { GraphiQL } from 'graphiql'; | ||
@@ -45,3 +45,4 @@ import { createGraphiQLFetcher } from '@graphiql/toolkit'; | ||
ReactDOM.render(document.getElementByID('graphiql'), <App />); | ||
const root = createRoot(document.getElementById('graphiql')); | ||
root.render(<App />); | ||
``` | ||
@@ -61,5 +62,5 @@ | ||
```ts | ||
```jsx | ||
import * as React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import { createRoot } from 'react-dom/client'; | ||
import { GraphiQL } from 'graphiql'; | ||
@@ -79,3 +80,4 @@ import { createGraphiQLFetcher } from '@graphiql/toolkit'; | ||
ReactDOM.render(document.getElementByID('graphiql'), <App />); | ||
const root = createRoot(document.getElementById('graphiql')); | ||
root.render(<App />); | ||
``` | ||
@@ -108,13 +110,12 @@ | ||
```ts | ||
```jsx | ||
const fetcher = createGraphiQLFetcher({ | ||
url: "https://localhost:3000", | ||
subscriptionUrl: "https://localhost:3001", | ||
wsConnectionParams: { Authorization: "token 1234" } | ||
}) | ||
url: 'https://localhost:3000', | ||
subscriptionUrl: 'https://localhost:3001', | ||
wsConnectionParams: { Authorization: 'token 1234' }, | ||
}); | ||
const App () { | ||
return <GraphiQL fetcher={fetcher} /> | ||
} | ||
const App = () => { | ||
return <GraphiQL fetcher={fetcher} />; | ||
}; | ||
``` | ||
@@ -143,5 +144,5 @@ | ||
```ts | ||
```jsx | ||
import * as React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import { createRoot } from 'react-dom/client'; | ||
import { GraphiQL } from 'graphiql'; | ||
@@ -165,3 +166,4 @@ import { createClient } from 'graphql-ws'; | ||
ReactDOM.render(document.getElementByID('graphiql'), <App />); | ||
const root = createRoot(document.getElementById('graphiql')); | ||
root.render(<App />); | ||
``` | ||
@@ -176,5 +178,5 @@ | ||
```ts | ||
```jsx | ||
import * as React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import { createRoot } from 'react-dom/client'; | ||
import { GraphiQL } from 'graphiql'; | ||
@@ -195,3 +197,4 @@ import { SubscriptionClient } from 'subscriptions-transport-ws'; | ||
ReactDOM.render(document.getElementByID('graphiql'), <App />); | ||
const root = createRoot(document.getElementById('graphiql')); | ||
root.render(<App />); | ||
``` | ||
@@ -209,5 +212,5 @@ | ||
```ts | ||
```jsx | ||
import * as React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import { createRoot } from 'react-dom/client'; | ||
import { GraphiQL } from 'graphiql'; | ||
@@ -226,3 +229,4 @@ import { fetch } from 'isomorphic-fetch'; | ||
ReactDOM.render(document.getElementByID('graphiql'), <App />); | ||
const root = createRoot(document.getElementById('graphiql')); | ||
root.render(<App />); | ||
``` | ||
@@ -229,0 +233,0 @@ |
@@ -18,3 +18,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
const subscription = observable.subscribe({ | ||
next: v => { | ||
next(v) { | ||
resolve(v); | ||
@@ -24,3 +24,3 @@ subscription.unsubscribe(); | ||
error: reject, | ||
complete: () => { | ||
complete() { | ||
reject(new Error('no value resolved')); | ||
@@ -27,0 +27,0 @@ }, |
@@ -33,3 +33,3 @@ import { createMultipartFetcher, createSimpleFetcher, isSubscriptionWithName, getWsFetcher, } from './lib'; | ||
? `Provided URL ${options.subscriptionUrl} failed` | ||
: `Please provide subscriptionUrl, wsClient or legacyClient option first.`}`); | ||
: 'Please provide subscriptionUrl, wsClient or legacyClient option first.'}`); | ||
} | ||
@@ -36,0 +36,0 @@ return wsFetcher(graphQLParams); |
@@ -72,3 +72,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
}; | ||
export const createWebsocketsFetcherFromClient = (wsClient) => (graphQLParams) => makeAsyncIterableIteratorFromSink(sink => wsClient.subscribe(graphQLParams, Object.assign(Object.assign({}, sink), { error: err => { | ||
export const createWebsocketsFetcherFromClient = (wsClient) => (graphQLParams) => makeAsyncIterableIteratorFromSink(sink => wsClient.subscribe(graphQLParams, Object.assign(Object.assign({}, sink), { error(err) { | ||
if (err instanceof CloseEvent) { | ||
@@ -75,0 +75,0 @@ sink.error(new Error(`Socket closed with event ${err.code} ${err.reason || ''}`.trim())); |
@@ -34,3 +34,3 @@ function isQuotaError(storage, e) { | ||
}, | ||
clear: () => { | ||
clear() { | ||
for (const key in window.localStorage) { | ||
@@ -37,0 +37,0 @@ if (key.indexOf(`${STORAGE_NAMESPACE}:`) === 0) { |
@@ -9,13 +9,14 @@ import { parse } from 'graphql'; | ||
this.updateHistory = (query, variables, headers, operationName) => { | ||
if (this.shouldSaveQuery(query, variables, headers, this.history.fetchRecent())) { | ||
this.history.push({ | ||
query, | ||
variables, | ||
headers, | ||
operationName, | ||
}); | ||
const historyQueries = this.history.items; | ||
const favoriteQueries = this.favorite.items; | ||
this.queries = historyQueries.concat(favoriteQueries); | ||
if (!this.shouldSaveQuery(query, variables, headers, this.history.fetchRecent())) { | ||
return; | ||
} | ||
this.history.push({ | ||
query, | ||
variables, | ||
headers, | ||
operationName, | ||
}); | ||
const historyQueries = this.history.items; | ||
const favoriteQueries = this.favorite.items; | ||
this.queries = historyQueries.concat(favoriteQueries); | ||
}; | ||
@@ -22,0 +23,0 @@ this.history = new QueryStore('queries', this.storage, this.maxHistoryLength); |
{ | ||
"name": "@graphiql/toolkit", | ||
"version": "0.8.4", | ||
"version": "0.9.0-canary-38c2c299.0", | ||
"description": "Utility to build a fetcher for GraphiQL", | ||
@@ -18,5 +18,4 @@ "contributors": [ | ||
"license": "MIT", | ||
"main": "dist/index.js", | ||
"module": "esm/index.js", | ||
"typings": "dist/index.d.ts", | ||
"types": "esm/index.d.ts", | ||
"scripts": {}, | ||
@@ -23,0 +22,0 @@ "dependencies": { |
@@ -20,3 +20,3 @@ import { | ||
const subscription = observable.subscribe({ | ||
next: v => { | ||
next(v) { | ||
resolve(v); | ||
@@ -26,3 +26,3 @@ subscription.unsubscribe(); | ||
error: reject, | ||
complete: () => { | ||
complete() { | ||
reject(new Error('no value resolved')); | ||
@@ -29,0 +29,0 @@ }, |
@@ -73,3 +73,2 @@ import { parse } from 'graphql'; | ||
url: '', | ||
// @ts-ignore | ||
wsClient: true, | ||
@@ -84,3 +83,2 @@ }); | ||
url: '', | ||
// @ts-ignore | ||
legacyClient: true, | ||
@@ -87,0 +85,0 @@ }); |
@@ -63,3 +63,3 @@ import type { Fetcher, CreateFetcherOptions } from './types'; | ||
? `Provided URL ${options.subscriptionUrl} failed` | ||
: `Please provide subscriptionUrl, wsClient or legacyClient option first.` | ||
: 'Please provide subscriptionUrl, wsClient or legacyClient option first.' | ||
}`, | ||
@@ -66,0 +66,0 @@ ); |
@@ -109,3 +109,3 @@ import { DocumentNode, visit } from 'graphql'; | ||
...sink, | ||
error: err => { | ||
error(err) { | ||
if (err instanceof CloseEvent) { | ||
@@ -112,0 +112,0 @@ sink.error( |
@@ -24,10 +24,12 @@ import { | ||
it('does not modify query with no fragments', () => { | ||
const query = ` | ||
const query = /* GraphQL */ ` | ||
query Test { | ||
id | ||
}`; | ||
const mergedQuery = stripWhitespace(` | ||
} | ||
`; | ||
const mergedQuery = stripWhitespace(/* GraphQL */ ` | ||
query Test { | ||
id | ||
}`); | ||
} | ||
`); | ||
expect(parseMergeAndPrint(query)).toBe(mergedQuery); | ||
@@ -38,20 +40,23 @@ expect(parseMergeAndPrint(query, schema)).toBe(mergedQuery); | ||
it('does inline simple nested fragment', () => { | ||
const query = ` | ||
const query = /* GraphQL */ ` | ||
query Test { | ||
...Fragment1 | ||
} | ||
fragment Fragment1 on Test { | ||
id | ||
}`; | ||
const mergedQuery = stripWhitespace(` | ||
} | ||
`; | ||
const mergedQuery = stripWhitespace(/* GraphQL */ ` | ||
query Test { | ||
...on Test { | ||
... on Test { | ||
id | ||
} | ||
}`); | ||
const mergedQueryWithSchema = stripWhitespace(` | ||
} | ||
`); | ||
const mergedQueryWithSchema = stripWhitespace(/* GraphQL */ ` | ||
query Test { | ||
id | ||
}`); | ||
} | ||
`); | ||
expect(parseMergeAndPrint(query)).toBe(mergedQuery); | ||
@@ -62,23 +67,24 @@ expect(parseMergeAndPrint(query, schema)).toBe(mergedQueryWithSchema); | ||
it('does inline triple nested fragment', () => { | ||
const query = ` | ||
const query = /* GraphQL */ ` | ||
query Test { | ||
...Fragment1 | ||
} | ||
fragment Fragment1 on Test { | ||
...Fragment2 | ||
} | ||
fragment Fragment2 on Test { | ||
...Fragment3 | ||
} | ||
fragment Fragment3 on Test { | ||
id | ||
}`; | ||
const mergedQuery = stripWhitespace(` | ||
} | ||
`; | ||
const mergedQuery = stripWhitespace(/* GraphQL */ ` | ||
query Test { | ||
...on Test { | ||
...on Test { | ||
...on Test { | ||
... on Test { | ||
... on Test { | ||
... on Test { | ||
id | ||
@@ -88,7 +94,9 @@ } | ||
} | ||
}`); | ||
const mergedQueryWithSchema = stripWhitespace(` | ||
} | ||
`); | ||
const mergedQueryWithSchema = stripWhitespace(/* GraphQL */ ` | ||
query Test { | ||
id | ||
}`); | ||
} | ||
`); | ||
expect(parseMergeAndPrint(query)).toBe(mergedQuery); | ||
@@ -99,3 +107,3 @@ expect(parseMergeAndPrint(query, schema)).toBe(mergedQueryWithSchema); | ||
it('does inline multiple fragments', () => { | ||
const query = ` | ||
const query = /* GraphQL */ ` | ||
query Test { | ||
@@ -106,30 +114,33 @@ ...Fragment1 | ||
} | ||
fragment Fragment1 on Test { | ||
id | ||
} | ||
fragment Fragment2 on Test { | ||
id | ||
} | ||
fragment Fragment3 on Test { | ||
id | ||
}`; | ||
const mergedQuery = stripWhitespace(` | ||
} | ||
`; | ||
const mergedQuery = stripWhitespace(/* GraphQL */ ` | ||
query Test { | ||
...on Test { | ||
... on Test { | ||
id | ||
} | ||
...on Test { | ||
... on Test { | ||
id | ||
} | ||
...on Test { | ||
... on Test { | ||
id | ||
} | ||
}`); | ||
const mergedQueryWithSchema = stripWhitespace(` | ||
} | ||
`); | ||
const mergedQueryWithSchema = stripWhitespace(/* GraphQL */ ` | ||
query Test { | ||
id | ||
}`); | ||
} | ||
`); | ||
expect(parseMergeAndPrint(query)).toBe(mergedQuery); | ||
@@ -140,3 +151,3 @@ expect(parseMergeAndPrint(query, schema)).toBe(mergedQueryWithSchema); | ||
it('removes duplicate fragment spreads', () => { | ||
const query = ` | ||
const query = /* GraphQL */ ` | ||
query Test { | ||
@@ -146,16 +157,19 @@ ...Fragment1 | ||
} | ||
fragment Fragment1 on Test { | ||
id | ||
}`; | ||
const mergedQuery = stripWhitespace(` | ||
} | ||
`; | ||
const mergedQuery = stripWhitespace(/* GraphQL */ ` | ||
query Test { | ||
...on Test { | ||
... on Test { | ||
id | ||
} | ||
}`); | ||
const mergedQueryWithSchema = stripWhitespace(` | ||
} | ||
`); | ||
const mergedQueryWithSchema = stripWhitespace(/* GraphQL */ ` | ||
query Test { | ||
id | ||
}`); | ||
} | ||
`); | ||
expect(parseMergeAndPrint(query)).toBe(mergedQuery); | ||
@@ -162,0 +176,0 @@ expect(parseMergeAndPrint(query, schema)).toBe(mergedQueryWithSchema); |
@@ -160,6 +160,3 @@ import { | ||
// comes from an origin parameter | ||
selectionSet: buildSelectionSet( | ||
fieldType as GraphQLOutputType, | ||
getDefaultFieldNames, | ||
), | ||
selectionSet: buildSelectionSet(fieldType!, getDefaultFieldNames), | ||
}; | ||
@@ -166,0 +163,0 @@ }), |
@@ -75,3 +75,3 @@ import { StorageAPI } from '../base'; | ||
const throwingStorage = new StorageAPI({ | ||
setItem: () => { | ||
setItem() { | ||
throw new DOMException('Terrible Error'); | ||
@@ -90,3 +90,3 @@ }, | ||
const throwingStorage = new StorageAPI({ | ||
setItem: () => { | ||
setItem() { | ||
throw new DOMException('Terrible Error', 'QuotaExceededError'); | ||
@@ -93,0 +93,0 @@ }, |
@@ -7,7 +7,6 @@ import { StorageAPI } from '../base'; | ||
count: number; | ||
map: any; | ||
map = {}; | ||
storage: Storage; | ||
constructor(shouldThrow: () => boolean) { | ||
this.shouldThrow = shouldThrow; | ||
this.map = {}; | ||
} | ||
@@ -103,3 +102,3 @@ | ||
shouldThrow = () => retryCounter < 3; | ||
store.push({ query: `finalItem` }); | ||
store.push({ query: 'finalItem' }); | ||
@@ -136,3 +135,3 @@ expect(store.items.length).toBe(8); | ||
shouldThrow = () => true; | ||
store.push({ query: `finalItem` }); | ||
store.push({ query: 'finalItem' }); | ||
@@ -139,0 +138,0 @@ expect(store.items.length).toBe(10); |
@@ -81,3 +81,3 @@ /** | ||
clear: () => { | ||
clear() { | ||
// We only want to clear the namespaced items | ||
@@ -84,0 +84,0 @@ for (const key in window.localStorage) { |
@@ -13,3 +13,6 @@ import { parse } from 'graphql'; | ||
constructor(private storage: StorageAPI, private maxHistoryLength: number) { | ||
constructor( | ||
private storage: StorageAPI, | ||
private maxHistoryLength: number, | ||
) { | ||
this.history = new QueryStore( | ||
@@ -76,3 +79,3 @@ 'queries', | ||
if ( | ||
this.shouldSaveQuery( | ||
!this.shouldSaveQuery( | ||
query, | ||
@@ -84,12 +87,13 @@ variables, | ||
) { | ||
this.history.push({ | ||
query, | ||
variables, | ||
headers, | ||
operationName, | ||
}); | ||
const historyQueries = this.history.items; | ||
const favoriteQueries = this.favorite.items; | ||
this.queries = historyQueries.concat(favoriteQueries); | ||
return; | ||
} | ||
this.history.push({ | ||
query, | ||
variables, | ||
headers, | ||
operationName, | ||
}); | ||
const historyQueries = this.history.items; | ||
const favoriteQueries = this.favorite.items; | ||
this.queries = historyQueries.concat(favoriteQueries); | ||
}; | ||
@@ -96,0 +100,0 @@ |
{ | ||
"extends": "../../resources/tsconfig.base.cjs.json", | ||
"extends": "../../resources/tsconfig.base.json", | ||
"compilerOptions": { | ||
"rootDir": "./src", | ||
"outDir": "./dist", | ||
"outDir": "./esm", | ||
"composite": true, | ||
"jsx": "react", | ||
"target": "es5", | ||
"baseUrl": ".", | ||
"strictPropertyInitialization": false | ||
"strictPropertyInitialization": false, | ||
"baseUrl": "." | ||
}, | ||
@@ -19,7 +18,4 @@ "include": ["src"], | ||
"**/*-test.ts", | ||
"**/*-test.js", | ||
"**/*.stories.js", | ||
"**/*.stories.ts", | ||
"**/*.stories.tsx" | ||
"**/*-test.js" | ||
] | ||
} |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
187208
88
2701