How to use the apollo-utilities.addTypenameToDocument function in apollo-utilities

To help you get started, we’ve selected a few apollo-utilities 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 Canner / apollo-link-firebase / src / rtdb / subscriptionLink.ts View on Github external
public request(operation: Operation, forward?: NextLink): Observable<FetchResult> {
    const {query} = operation;
    const isRtdbQuery = hasDirectives(['rtdbSub'], query);

    if (!isRtdbQuery && forward) {
      return forward(operation);
    }

    const queryWithTypename = addTypenameToDocument(query);
    const mainDefinition = getMainDefinition(query);

    const context: ResolverContext = {
      database: this.database,
      findType: fieldDirectives =>
        (fieldDirectives.rtdbSub && fieldDirectives.rtdbSub.type) ||
        (fieldDirectives.rtdbQuery && fieldDirectives.rtdbQuery.type),
      exportVal: {}
    };

    // Subscription operations must have exactly one root field.
    const onlyRootField: FieldNode = mainDefinition.selectionSet.selections[0] as FieldNode;

    // get directives
    const directives = getDirectiveInfoFromField(onlyRootField, operation.variables);
    const rtdbDirectives: SubDirectiveArgs = directives.rtdbSub as any;
github strvcom / dep-manager-web / src / utils / RestLink.ts View on Github external
public request (operation: Operation, forward?: NextLink) {
    const isRestQuery = hasDirectives(['rest'], operation.query)
    if (!isRestQuery && forward) return forward(operation)
    const nonRestQuery = removeRestDirective(operation.query)
    const typeNamedQuery = addTypenameToDocument(operation.query)
    const observable =
      nonRestQuery && forward
        ? // tslint:disable-next-line:prefer-object-spread
        forward(Object.assign(operation, { query: nonRestQuery }))
        : Observable.of<FetchResult>({ data: {} })
    return observable.flatMap(
      ({ data, ...rest }) =>
        new Observable<FetchResult>(subscriber => {
          graphql(
            resolver,
            typeNamedQuery,
            data,
            this.resolverMap,
            operation.variables
          )
            .then(resolvedData => {
github sysgears / apollo-universal-starter-kit / modules / testing / client-react / Renderer.tsx View on Github external
public _getSubscriptions(query: DocumentNode, variables?: any) {
    if (!query) {
      return this.subscriptionQueries;
    }
    const queryStr = print(addTypenameToDocument(query));
    const key = JSON.stringify({
      query: queryStr,
      variables: variables || {}
    });
    const subscriptions = (!variables ? this.subscriptionQueries[queryStr] : this.subscriptions[key]) || [];

    const handlers = this.handlers;

    return subscriptions.map((subId: number) => {
      const res = {
        next(value: any) {
          return handlers[subId].handler.next(value);
        },
        error(errorValue: any) {
          return handlers[subId].handler.error(errorValue);
        }
github apollographql / react-apollo / packages / testing / src / mocks / mockLink.ts View on Github external
function requestToKey(request: GraphQLRequest, addTypename: Boolean): string {
  const queryString =
    request.query &&
    print(addTypename ? addTypenameToDocument(request.query) : request.query);
  const requestKey = { query: queryString };
  return JSON.stringify(requestKey);
}
github apollographql / react-apollo / packages / testing / lib / mocks / mockLink.js View on Github external
function requestToKey(request, addTypename) {
    var queryString = request.query &&
        print(addTypename ? addTypenameToDocument(request.query) : request.query);
    var requestKey = { query: queryString };
    return JSON.stringify(requestKey);
}
var MockLink = (function (_super) {
github Canner / canner / packages / canner-graphql-interface / src / link.ts View on Github external
if (resolverMap) {
          const resolve = resolverMap[fieldName];
          if (resolve) {
            return resolve(rootValue, args, context, info);
          }
        }

        const fieldValue = rootValue[info.resultKey];

        if (fieldValue !== undefined) {
          return fieldValue;
        }
        return null;
      };

      const queryWithTypename = addTypenameToDocument(query);
      const connectors = multiConnectors
        ? mapValues(multiConnectors, connector => {
          return new DataLoaderConnector({keys: schemaKeys, connector});
        })
        : mapValues(schema, (value, key) => {
          return new DataLoaderConnector({keys: schemaKeys, connector: singleConnector});
        });

      return new Observable(observer => {
        graphql(
          graphqlResolver,
          queryWithTypename,
          {},
          {document: queryWithTypename, connectors},
          operation.variables
        )
github newsuk / times-components / packages / provider / fixtures / author-profile / fixture-generator.js View on Github external
const makeAuthorMock = ({ count, withImages, slug, delay = 1000 }) => ({
  delay,
  request: {
    query: addTypenameToDocument(authorProfileQuery),
    variables: {
      slug
    }
  },
  result: {
    data: {
      author: {
        ...makeAuthor({ count, withImages })
      }
    }
  }
});
github newsuk / times-components / packages / provider-queries / src / author-articles-no-images.js View on Github external
import { addTypenameToDocument } from "apollo-utilities";
import authorArticlesNoImagesQuery from "./author_articles_no_images.graphql";

export default addTypenameToDocument(authorArticlesNoImagesQuery);

export const propsToVariables = ({
  longSummaryLength,
  pageSize,
  page,
  shortSummaryLength,
  slug
}) => ({
  first: pageSize,
  longSummaryLength,
  shortSummaryLength,
  skip: pageSize * (page - 1),
  slug
});
github newsuk / times-components / packages / provider-queries / src / get-tokenised-article-url.js View on Github external
import { addTypenameToDocument } from "apollo-utilities";
import getTokenisedArticleUrl from "./get_tokenised_article_url.graphql";

export default addTypenameToDocument(getTokenisedArticleUrl);
github newsuk / times-components / packages / provider-queries / src / author-articles-with-images.js View on Github external
import { addTypenameToDocument } from "apollo-utilities";
import authorArticlesWithImages from "./author_articles_with_images.graphql";

export default addTypenameToDocument(authorArticlesWithImages);

export const propsToVariables = ({
  slug,
  pageSize,
  page,
  articleImageRatio = "3:2"
}) => ({
  first: pageSize,
  imageRatio: articleImageRatio,
  skip: pageSize * (page - 1),
  slug
});