MCPcopy
hub / github.com/graphql/graphiql / run

Function run

packages/graphiql-react/src/execution.tsx:110–265  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

108 };
109
110 const run: ExecutionContextType['run'] = async () => {
111 if (!queryEditor || !responseEditor) {
112 return;
113 }
114
115 // If there's an active subscription, unsubscribe it and return
116 if (subscription) {
117 stop();
118 return;
119 }
120
121 const setResponse = (value: string) => {
122 responseEditor.setValue(value);
123 updateActiveTabValues({ response: value });
124 };
125
126 queryIdRef.current += 1;
127 const queryId = queryIdRef.current;
128
129 // Use the edited query after autoCompleteLeafs() runs or,
130 // in case autoCompletion fails (the function returns undefined),
131 // the current query from the editor.
132 let query = autoCompleteLeafs() || queryEditor.getValue();
133
134 const variablesString = variableEditor?.getValue();
135 let variables: Record<string, unknown> | undefined;
136 try {
137 variables = tryParseJsonObject({
138 json: variablesString,
139 errorMessageParse: 'Variables are invalid JSON',
140 errorMessageType: 'Variables are not a JSON object.',
141 });
142 } catch (error) {
143 setResponse(error instanceof Error ? error.message : `${error}`);
144 return;
145 }
146
147 const headersString = headerEditor?.getValue();
148 let headers: Record<string, unknown> | undefined;
149 try {
150 headers = tryParseJsonObject({
151 json: headersString,
152 errorMessageParse: 'Headers are invalid JSON',
153 errorMessageType: 'Headers are not a JSON object.',
154 });
155 } catch (error) {
156 setResponse(error instanceof Error ? error.message : `${error}`);
157 return;
158 }
159
160 if (externalFragments) {
161 const fragmentDependencies = queryEditor.documentAST
162 ? getFragmentDependenciesForAST(
163 queryEditor.documentAST,
164 externalFragments,
165 )
166 : [];
167 if (fragmentDependencies.length > 0) {

Callers 4

test.spec.tsFile · 0.50
ExplorerPluginFunction · 0.50
ExecuteButtonFunction · 0.50
runAtCursorFunction · 0.50

Calls 10

isObservableFunction · 0.90
isAsyncIterableFunction · 0.90
formatErrorFunction · 0.90
stopFunction · 0.85
tryParseJsonObjectFunction · 0.85
setResponseFunction · 0.85
handleAsyncResultsFunction · 0.85
handleResponseFunction · 0.85
fetcherFunction · 0.50

Tested by

no test coverage detected