How to use the graphql-tag/printer.print function in graphql-tag

To help you get started, we’ve selected a few graphql-tag 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 apollographql / apollo-client / src / QueryManager.ts View on Github external
queryId: string,
    options: WatchQueryOptions
  ): Promise {
    const {
      variables,
      forceFetch = false,
      returnPartialData = false,
      noFetch = false,
    } = options;

    const {
      queryDoc,
      fragmentMap,
    } = this.transformQueryDocument(options);
    const queryDef = getQueryDefinition(queryDoc);
    const queryString = print(queryDoc);
    const querySS = {
      id: 'ROOT_QUERY',
      typeName: 'Query',
      selectionSet: queryDef.selectionSet,
    } as SelectionSetWithRoot;

    // If we don't use diffing, then these will be the same as the original query, other than
    // the queryTransformer that could have been applied.
    let minimizedQueryString = queryString;
    let minimizedQuery = querySS;
    let minimizedQueryDoc = queryDoc;
    let storeResult: any;

    // If this is not a force fetch, we want to diff the query against the
    // store before we fetch it from the network interface.
    if (!forceFetch) {
github apollographql / apollo-client / test / queryMerging.ts View on Github external
const query = gql`
      query author {
        firstName
        lastName
      }`;
    const expQuery = gql`
      query ___composed___author {
        firstName
        lastName
      }`;

    const queryDef = getQueryDefinition(query);
    const expQueryDefinition = getQueryDefinition(expQuery);

    const resultQueryDefinition = addPrefixToQuery('___composed___', queryDef);
    assert.deepEqual(print(resultQueryDefinition), print(expQueryDefinition));
  });
github apollographql / apollo-client / test / queryMerging.ts View on Github external
}
      }
      fragment authorDetails on Author {
        firstName
        lastName
      }`;
    const queryDef = getQueryDefinition(query);
    const fragmentDefinition = getFragmentDefinitions(query)[0];
    const aliasName = getOperationDefinitionName(queryDef, 2);
    const exp = getFragmentDefinitions(gql`
      fragment ___authorStuff___requestIndex_2___authorDetails on Author {
        ___authorStuff___requestIndex_2___fieldIndex_0: firstName
        ___authorStuff___requestIndex_2___fieldIndex_1: lastName
      }`)[0];
    const res = applyAliasNameToFragment(fragmentDefinition, aliasName, 0);
    assert.equal(print(res), print(exp));
  });
github apollographql / apollo-client / test / queryMerging.ts View on Github external
query authorStuff {
        author {
          ...authorDetails
        }
     }`;
    const exp = gql`
      query {
        author {
          ...___authorStuff___requestIndex_2___authorDetails
        }
      }`;
    const queryDef = getQueryDefinition(doc);
    const expDef = getQueryDefinition(exp);
    const res = renameFragmentSpreads(queryDef.selectionSet,
                                      '___authorStuff___requestIndex_2');
    assert.equal(print(res), print(expDef.selectionSet));
  });
github zanettin / inferno-apollo / src / test-utils.tsx View on Github external
public fireResult(id: number) {
    const handler = this.handlersById[id];
    if (this.mockedSubscriptionsById.hasOwnProperty(id.toString())) {
      const subscription = this.mockedSubscriptionsById[id];
      if (subscription.results.length === 0) {
        throw new Error(`No more mocked subscription responses for the query: ` +
        `${print(subscription.request.query)}, variables: ${JSON.stringify(subscription.request.variables)}`);
      }
      const response = subscription.results.shift();
      setTimeout(() => {
        handler(response.error, response.result);
      }, response.delay ? response.delay : 0);
    } else {
      throw new Error('Network interface does not have subscription associated with this id.');
    }
  }
github apollographql / apollo-client / test / mocks / mockNetworkInterface.ts View on Github external
public fireResult(id: number) {
    const handler = this.handlersById[id];
    if (this.mockedSubscriptionsById.hasOwnProperty(id.toString())) {
      const subscription = this.mockedSubscriptionsById[id];
      if (subscription.results.length === 0) {
        throw new Error(`No more mocked subscription responses for the query: ` +
        `${print(subscription.request.query)}, variables: ${JSON.stringify(subscription.request.variables)}`);
      }
      const response = subscription.results.shift();
      setTimeout(() => {
        handler(response.error, response.result);
      }, response.delay ? response.delay : 0);
    } else {
      throw new Error('Network interface does not have subscription associated with this id.');
    }
  }
github DeligenceTechnologies / Meteor-Apollo-with-MongoDB-MySQL / meteor-apollo-mognodb-mysql / node_modules / apollo-client / networkInterface.js View on Github external
return mapValues(request, function (val, key) {
        return key === 'query' ? printer_1.print(val) : val;
    });
}
github notadamking / React-Realtime-Chat / client / utils / subscriptions.js View on Github external
subscribe: (request, handler) => {
      return wsClient.subscribe({
        query: print(request.query),
        variables: request.variables,
      }, handler);
    },
    unsubscribe: (id) => {
github Thorium-Sim / thorium / src / helpers / subscriptions.js View on Github external
subscribe(request, handler) {
      return wsClient.subscribe({
        query: print(request.query),
        variables: request.variables,
      }, handler);
    },
    unsubscribe(id) {

graphql-tag

A JavaScript template literal tag that parses GraphQL queries

MIT
Latest version published 3 years ago

Package Health Score

83 / 100
Full package analysis

Similar packages