How to use the apollo-utilities.getOperationDefinition 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 apollographql / apollo-client / packages / apollo-client / src / core / QueryManager.ts View on Github external
public startGraphQLSubscription(
    options: SubscriptionOptions,
  ): Observable {
    const { query } = options;
    let transformedDoc = this.dataStore.getCache().transformDocument(query);

    const variables = assign(
      {},
      getDefaultValues(getOperationDefinition(query)),
      options.variables,
    );

    const request: Request = {
      query: transformedDoc,
      variables,
      operationName: getOperationName(transformedDoc) || undefined,
    };

    let sub: Subscription;
    let observers: Observer[] = [];

    return new Observable(observer => {
      observers.push(observer);

      // If this is the first observer, actually initiate the network subscription
github apollographql / apollo-client / packages / apollo-client / src / core / ObservableQuery.ts View on Github external
shouldSubscribe?: boolean;
  }) {
    super((observer: Observer>) =>
      this.onSubscribe(observer),
    );

    // active state
    this.isTornDown = false;

    // query information
    this.options = options;
    this.variables = options.variables || ({} as TVariables);
    this.queryId = queryManager.generateQueryId();
    this.shouldSubscribe = shouldSubscribe;

    const opDef = getOperationDefinition(options.query);
    this.queryName = opDef && opDef.name && opDef.name.value;

    // related classes
    this.queryManager = queryManager;
  }
github apollographql / apollo-client / packages / apollo-cache-inmemory / src / writeToStore.ts View on Github external
document,
    store = defaultNormalizedCacheFactory(),
    variables,
    dataIdFromObject,
    fragmentMatcherFunction,
  }: {
    dataId: string;
    result: any;
    document: DocumentNode;
    store?: NormalizedCache;
    variables?: Object;
    dataIdFromObject?: IdGetter;
    fragmentMatcherFunction?: FragmentMatcher;
  }): NormalizedCache {
    // XXX TODO REFACTOR: this is a temporary workaround until query normalization is made to work with documents.
    const operationDefinition = getOperationDefinition(document)!;

    try {
      return this.writeSelectionSetToStore({
        result,
        dataId,
        selectionSet: operationDefinition.selectionSet,
        context: {
          store,
          processedData: {},
          variables: assign(
            {},
            getDefaultValues(operationDefinition),
            variables,
          ),
          dataIdFromObject,
          fragmentMap: createFragmentMap(getFragmentDefinitions(document)),
github apollographql / apollo-client / packages / apollo-client / src / core / QueryManager.ts View on Github external
const forLink = removeConnectionDirectiveFromDocument(
        cache.transformForLink(transformed));

      const clientQuery = this.localState.clientQuery(transformed);
      const serverQuery = this.localState.serverQuery(forLink);

      const cacheEntry = {
        document: transformed,
        // TODO These two calls (hasClientExports and shouldForceResolvers)
        // could probably be merged into a single traversal.
        hasClientExports: hasClientExports(transformed),
        hasForcedResolvers: this.localState.shouldForceResolvers(transformed),
        clientQuery,
        serverQuery,
        defaultVars: getDefaultValues(
          getOperationDefinition(transformed)
        ) as OperationVariables,
      };

      const add = (doc: DocumentNode | null) => {
        if (doc && !transformCache.has(doc)) {
          transformCache.set(doc, cacheEntry);
        }
      }
      // Add cacheEntry to the transformCache using several different keys,
      // since any one of these documents could end up getting passed to the
      // transform method again in the future.
      add(document);
      add(transformed);
      add(clientQuery);
      add(serverQuery);
    }
github Grantimus9 / vuegraphqlphx / assets / node_modules / apollo-client / core / QueryManager.js View on Github external
QueryManager.prototype.startGraphQLSubscription = function (options) {
        var _this = this;
        var query = options.query;
        var cache = this.dataStore.getCache();
        var transformedDoc = cache.transformDocument(query);
        var variables = assign({}, getDefaultValues(getOperationDefinition(query)), options.variables);
        var request = {
            query: transformedDoc,
            variables: variables,
            operationName: getOperationName(transformedDoc) || undefined,
        };
        var sub;
        var observers = [];
        return new Observable(function (observer) {
            observers.push(observer);
            if (observers.length === 1) {
                var handler = {
                    next: function (result) {
                        _this.dataStore.markSubscriptionResult(result, transformedDoc, variables);
                        _this.broadcastQueries();
                        observers.forEach(function (obs) {
                            if (obs.next)
github coralproject / talk / client / coral-framework / graphql / reduceDocument.js View on Github external
export default function reduceDocument(document, options = {}) {
  const mainDefinition = getMainDefinition(document);
  const fragments = getFragmentDefinitions(document);
  const operationDefinition = getOperationDefinition(document);
  const path = operationDefinition
    ? operationDefinition.operation
    : `type.${mainDefinition.typeCondition.name.value}`;

  const execContext = {
    rawFragmentMap: createFragmentMap(fragments),
    fragmentMap: options.fragmentMap || {},
    variables: options.variables,
    typeGetter: options.typeGetter || (() => null),
  };

  return {
    kind: 'Document',
    definitions: [transformDefinition(mainDefinition, execContext, path)],
  };
}
github Grantimus9 / vuegraphqlphx / assets / node_modules / apollo-cache-inmemory / lib / writeToStore.js View on Github external
export function writeResultToStore(_a) {
    var dataId = _a.dataId, result = _a.result, document = _a.document, _b = _a.storeFactory, storeFactory = _b === void 0 ? defaultNormalizedCacheFactory : _b, _c = _a.store, store = _c === void 0 ? storeFactory() : _c, variables = _a.variables, dataIdFromObject = _a.dataIdFromObject, fragmentMatcherFunction = _a.fragmentMatcherFunction;
    var operationDefinition = getOperationDefinition(document);
    var selectionSet = operationDefinition.selectionSet;
    var fragmentMap = createFragmentMap(getFragmentDefinitions(document));
    variables = assign({}, getDefaultValues(operationDefinition), variables);
    try {
        return writeSelectionSetToStore({
            result: result,
            dataId: dataId,
            selectionSet: selectionSet,
            context: {
                store: store,
                storeFactory: storeFactory,
                processedData: {},
                variables: variables,
                dataIdFromObject: dataIdFromObject,
                fragmentMap: fragmentMap,
                fragmentMatcherFunction: fragmentMatcherFunction,
github awslabs / aws-mobile-appsync-sdk-js / packages / aws-appsync / src / link / offline-link.ts View on Github external
return new Observable(observer => {
            const { offline: { online } } = this.store.getState();
            const { operation: operationType } = getOperationDefinition(operation.query);
            const isMutation = operationType === 'mutation';
            const isQuery = operationType === 'query';

            if (!online && isQuery) {
                const data = processOfflineQuery(operation, this.store);

                observer.next({ data });
                observer.complete();

                return () => null;
            }

            if (isMutation) {
                const { AASContext: { doIt = false } = {}, cache } = operation.getContext();

                if (!doIt) {