Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return new Promise((resolve, reject) => {
try {
pipe(
client.executeQuery(createRequest(query, variables)),
subscribe(({ data, error }) => {
if (error) {
reject(error);
} else {
resolve(data);
}
})
);
// eslint-disable-next-line no-empty
} catch (err) {}
});
}
const handleMessage = (client: Client) => (message: any) => {
if (message.type === "request") {
const isMutation = /(^|\W)+mutation\W/.test(message.query);
const execFn = isMutation ? client.executeMutation : client.executeQuery;
pipe(
execFn(createRequest(message.query), {
meta: { source: "Devtools" }
}),
toPromise
);
}
};
export function gqlSubscription(
client: Client,
q: string,
subscriber: GqlSubscriber,
options: GqlSubscriptionOptions = {},
) {
const { variables, headers = {} } = options;
const request = createRequest(q, variables);
const response = client.executeSubscription(request, { fetchOptions: { headers } });
const [teardown] = pipe(
response,
subscribe(({ data, error }) => {
subscriber(data, error);
}),
);
return teardown;
}
useEffect(() => {
setResult(prev => ({ ...prev, fetching: true }));
const request = createRequest(query, variables);
const [teardown] = pipe(
urqlClient.executeQuery(request),
subscribe(({ data, error }) => {
setResult({ fetching: false, data, error });
})
);
return teardown;
}, []);
mutate(q, options = {}) {
const { variables } = options;
const request = createRequest(q, variables);
const response = client.executeMutation(request);
return pipeToPromise(response);
},
subscribe(q, subscriber, options = {}) {
export function gqlQuery(client: Client, q: string, options: GqlQueryOptions = {}) {
const { variables, cache, headers = {} } = options;
const request = createRequest(q, variables);
const response = client.executeQuery(request, { requestPolicy: cache, fetchOptions: { headers } });
return pipeToPromise(response);
}
subscribe(q, subscriber, options = {}) {
const { variables } = options;
const request = createRequest(q, variables);
const response = client.executeSubscription(request);
const [teardown] = pipe(
response,
subscribe(({ data, error }) => {
subscriber(data, error);
}),
);
return teardown;
},
};
query(q, options = {}) {
const { variables, cache } = options;
const request = createRequest(q, variables);
const response = client.executeQuery(request, { requestPolicy: cache });
return pipeToPromise(response);
},
mutate(q, options = {}) {
export function gqlMutation(client: Client, q: string, options: GqlMutationOptions = {}) {
const { variables, headers = {} } = options;
const request = createRequest(q, variables);
const response = client.executeMutation(request, { fetchOptions: { headers } });
return pipeToPromise(response);
}