How to use the urql.createRequest function in urql

To help you get started, we’ve selected a few urql examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github CrystallizeAPI / crystallize-frontend-boilerplate / lib / graph / execute-queries.js View on Github external
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) {}
  });
}
github FormidableLabs / urql-devtools / src / exchange / exchange.ts View on Github external
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
    );
  }
};
github smapiot / piral / src / packages / piral-urql / src / queries.ts View on Github external
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;
}
github CrystallizeAPI / crystallize-frontend-boilerplate / lib / graph / use-query.js View on Github external
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;
  }, []);
github smapiot / piral / packages / piral-ext / src / gql / create.ts View on Github external
mutate(q, options = {}) {
      const { variables } = options;
      const request = createRequest(q, variables);
      const response = client.executeMutation(request);
      return pipeToPromise(response);
    },
    subscribe(q, subscriber, options = {}) {
github smapiot / piral / src / packages / piral-urql / src / queries.ts View on Github external
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);
}
github smapiot / piral / packages / piral-ext / src / gql / create.ts View on Github external
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;
    },
  };
github smapiot / piral / packages / piral-ext / src / gql / create.ts View on Github external
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 = {}) {
github smapiot / piral / src / packages / piral-urql / src / queries.ts View on Github external
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);
}

urql

A highly customizable and versatile GraphQL client for React

MIT
Latest version published 16 days ago

Package Health Score

98 / 100
Full package analysis