Skip to content

Commit

Permalink
fix(toolkit): operationName is optional (#2373)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjie authored May 5, 2022
1 parent e823697 commit 5b2c1b2
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 13 deletions.
6 changes: 6 additions & 0 deletions .changeset/twelve-dogs-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'graphiql': patch
'@graphiql/toolkit': patch
---

Fix TypeScript definition of FetcherParams to reflect that operationName is optional
2 changes: 1 addition & 1 deletion packages/graphiql-2-rfc-context/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export type SchemaConfig = {

export type FetcherParams = {
query: string;
operationName?: string;
operationName?: string | null;
variables?: string;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function createGraphiQLFetcher(options: CreateFetcherOptions): Fetcher {
}
const isSubscription = isSubscriptionWithName(
fetcherOpts?.documentAST!,
graphQLParams.operationName,
graphQLParams.operationName || undefined,
);
if (isSubscription) {
if (!wsFetcher) {
Expand Down
2 changes: 1 addition & 1 deletion packages/graphiql-toolkit/src/create-fetcher/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import type {
*/
export const isSubscriptionWithName = (
document: DocumentNode,
name: string,
name: string | undefined,
): boolean => {
let isSubscription = false;
visit(document, {
Expand Down
2 changes: 1 addition & 1 deletion packages/graphiql-toolkit/src/create-fetcher/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export type Unsubscribable = {

export type FetcherParams = {
query: string;
operationName: string;
operationName?: string | null;
variables?: any;
};

Expand Down
18 changes: 9 additions & 9 deletions packages/graphiql/src/components/GraphiQL.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1338,9 +1338,9 @@ export class GraphiQL extends React.Component<GraphiQLProps, GraphiQLState> {

private async _fetchQuery(
query: string,
variables: string,
headers: string,
operationName: string,
variables: string | undefined,
headers: string | undefined,
operationName: string | undefined,
shouldPersistHeaders: boolean,
cb: (value: FetcherResult) => any,
): Promise<null | Unsubscribable> {
Expand Down Expand Up @@ -1493,7 +1493,7 @@ export class GraphiQL extends React.Component<GraphiQLProps, GraphiQLState> {
// Use the edited query after autoCompleteLeafs() runs or,
// in case autoCompletion fails (the function returns undefined),
// the current query from the editor.
const editedQuery = this.autoCompleteLeafs() || this.state.query;
const editedQuery = this.autoCompleteLeafs() || this.state.query || '';
const variables = this.state.variables;
const headers = this.state.headers;
const shouldPersistHeaders = this.state.shouldPersistHeaders;
Expand Down Expand Up @@ -1537,11 +1537,11 @@ export class GraphiQL extends React.Component<GraphiQLProps, GraphiQLState> {

// _fetchQuery may return a subscription.
const subscription = await this._fetchQuery(
editedQuery as string,
variables as string,
headers as string,
operationName as string,
shouldPersistHeaders as boolean,
editedQuery,
variables,
headers,
operationName,
shouldPersistHeaders,
(result: FetcherResult) => {
if (queryID === this._editorQueryID) {
let maybeMultipart = Array.isArray(result) ? result : false;
Expand Down

0 comments on commit 5b2c1b2

Please sign in to comment.