How to use graphql-tag - 10 common examples

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 dotansimha / graphql-code-generator / packages / plugins / other / visitor-plugin-common / src / client-side-base-visitor.ts View on Github external
protected _gql(node: FragmentDefinitionNode | OperationDefinitionNode): string {
    const doc = this._prepareDocument(`
    ${
      print(node)
        .split('\\')
        .join('\\\\') /* Re-escape escaped values in GraphQL syntax */
    }
    ${this._includeFragments(this._transformFragments(node))}`);

    if (this.config.documentMode === DocumentMode.documentNode) {
      const gqlObj = gqlTag(doc);

      if (gqlObj && gqlObj['loc']) {
        delete gqlObj.loc;
      }

      return JSON.stringify(gqlObj);
    } else if (this.config.documentMode === DocumentMode.string) {
      return '`' + doc + '`';
    }

    return 'gql`' + doc + '`';
  }
github VulcanJS / Vulcan / packages / nova-lib / lib / modules / fragments.js View on Github external
if (!fragment) {
    throw new Error(`Fragment "${fragmentName}" not registered.`)
  }

  // pad the literals array with line returns for each subFragments
  const literals = [fragment.fragmentText, ...fragment.subFragments.map(x => '\n')];
  
  // console.log(`// getFragment: ${parentFragmentName ? parentFragmentName + ' > ' : ''}${fragmentName}`)
  // console.log('fragmentText: ', fragment.fragmentText)
  // console.log('subFragments:', fragment.subFragments)
  // console.log('length:', fragment.subFragments.length)

  // the gql function expects an array of literals as first argument, and then sub-fragments as other arguments
  const gqlArguments = [literals, ...fragment.subFragments.map(f => getFragment(f, fragmentName))];

  return gql.apply(null, gqlArguments);
}
github braposo / graphql-css / src / index.js View on Github external
return cxs(el)(props => {
        try {
            const parsedQuery = isGqlQuery(query)
                ? query
                : internalGql(buildQuery(interleave(query, interpolations), props).join(""));

            return smoosh(graphql(resolver, parsedQuery, styles));
        } catch (e) {
            // eslint-disable-next-line no-console
            console.error("Not a valid gql query. Did you forget a prop?");
            return {};
        }
    });
};
github erxes / erxes / src / modules / deals / containers / Pipeline.tsx View on Github external
// get pipeline expanding config from localStorage
    const expandConfig = this.getConfig();

    const extendedProps = {
      ...this.props,
      stages: this.state.stages,
      isExpanded: expandConfig[index],
      onToggle: value => this.setConfig(value)
    };

    return ;
  }
}

const PipelineContainerWithData = compose(
  graphql(gql(mutations.stagesUpdateOrder), {
    name: 'stagesUpdateOrderMutation'
  }),
  graphql(gql(mutations.stagesChange), {
    name: 'stagesChangeMutation'
  })
)(PipelineContainer);

class StagesWithPipeline extends React.Component<{ stagesQuery: any }> {
  render() {
    const { stagesQuery } = this.props;

    if (stagesQuery.loading) {
      return ;
    }

    const stages = stagesQuery.dealStages;
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 partyparrot / codetours / .storybook / jestGraphql.js View on Github external
process(src) {
    // call directly the webpack loader with a mocked context
    // as graphql-tag/loader leverages `this.cacheable()`
    return loader.call({ cacheable() {} }, src);
  },
};
github remind101 / jest-transform-graphql / index.js View on Github external
process(src) {
    // call directly the webpack loader with a mocked context 
    // as graphql-tag/loader leverages `this.cacheable()`
    return loader.call({ cacheable() {} }, src);
  },
};
github sebastian-software / edge / packages / jest-preset-edge / transform / graphql.js View on Github external
process(source) {
    return loader.call({
      cacheable() {
        // empty
      }
    }, source)
  }
}
github VulcanJS / Vulcan / packages / vulcan-lib / lib / modules / fragments.js View on Github external
export const getFragmentObject = (fragmentText, subFragments) => {
  // pad the literals array with line returns for each subFragments
  const literals = subFragments ? [fragmentText, ...subFragments.map(x => '\n')] : [fragmentText];

  // the gql function expects an array of literals as first argument, and then sub-fragments as other arguments
  const gqlArguments = subFragments ? [literals, ...subFragments.map(subFragmentName => {
    // return subfragment's gql fragment
    if (!Fragments[subFragmentName] || !Fragments[subFragmentName].fragmentObject) {
      throw new Error(`Subfragment “${subFragmentName}” of fragment “${extractFragmentName(fragmentText)}” has not been initialized yet.`);
    }
    return Fragments[subFragmentName].fragmentObject;
  })] : [literals];

  return gql.apply(null, gqlArguments);
}
github LessWrong2 / Lesswrong2 / packages / vulcan-lib / lib / modules / fragments.js View on Github external
export const getFragmentObject = (fragmentText, subFragments) => {
  // pad the literals array with line returns for each subFragments
  const literals = subFragments ? [fragmentText, ...subFragments.map(x => '\n')] : [fragmentText];

  // the gql function expects an array of literals as first argument, and then sub-fragments as other arguments
  const gqlArguments = subFragments ? [literals, ...subFragments.map(subFragmentName => {
    // return subfragment's gql fragment
    if (!Fragments[subFragmentName] || !Fragments[subFragmentName].fragmentObject) {
      throw new Error(`Subfragment “${subFragmentName}” of fragment “${extractFragmentName(fragmentText)}” has not been initialized yet.`);
    }
    return Fragments[subFragmentName].fragmentObject;
  })] : [literals];

  return gql.apply(null, gqlArguments);
};

graphql-tag

A JavaScript template literal tag that parses GraphQL queries

MIT
Latest version published 3 years ago

Package Health Score

80 / 100
Full package analysis

Similar packages