How to use the ts-invariant.invariant function in ts-invariant

To help you get started, we’ve selected a few ts-invariant 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 watchQuery(
    options: WatchQueryOptions,
    shouldSubscribe = true,
  ): ObservableQuery {
    invariant(
      options.fetchPolicy !== 'standby',
      'client.watchQuery cannot be called with fetchPolicy set to "standby"',
    );

    // assign variable default values if supplied
    options.variables = this.getVariables(options.query, options.variables);

    if (typeof options.notifyOnNetworkStatusChange === 'undefined') {
      options.notifyOnNetworkStatusChange = false;
    }

    let transformedOptions = { ...options } as WatchQueryOptions;

    return new ObservableQuery({
      queryManager: this,
      options: transformedOptions,
github apollographql / apollo-client / packages / apollo-utilities / src / directives.ts View on Github external
invariant(
      directiveArguments && directiveArguments.length === 1,
      `Incorrect number of arguments for the @${directiveName} directive.`,
    );

    const ifArgument = directiveArguments[0];
    invariant(
      ifArgument.name && ifArgument.name.value === 'if',
      `Invalid argument for the @${directiveName} directive.`,
    );

    const ifValue: ValueNode = ifArgument.value;

    // means it has to be a variable value if this is a valid @skip or @include directive
    invariant(
      ifValue &&
        (ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'),
      `Argument for the @${directiveName} directive must be a variable or a boolean value.`,
    );

    return { directive, ifArgument };
  }) : [];
}
github apollographql / apollo-client / packages / apollo-cache-inmemory / src / writeToStore.ts View on Github external
// data from that id with the data we're about to write in the store.
      storeObject = store.get(dataId);
      const escapedId =
        storeObject && (storeObject[storeFieldName] as IdValue | undefined);
      if (escapedId !== storeValue && isIdValue(escapedId)) {
        const hadTypename = escapedId.typename !== undefined;
        const hasTypename = typename !== undefined;
        const typenameChanged =
          hadTypename && hasTypename && escapedId.typename !== typename;

        // If there is already a real id in the store and the current id we
        // are dealing with is generated, we throw an error.
        // One exception we allow is when the typename has changed, which occurs
        // when schema defines a union, both with and without an ID in the same place.
        // checks if we "lost" the read id
        invariant(
          !generated || escapedId.generated || typenameChanged,
          `Store error: the application attempted to write an object with no provided id but the store already contains an id of ${
            escapedId.id
          } for this object. The selectionSet that was trying to be written is:\n${
            JSON.stringify(field)
          }`,
        );

        // checks if we "lost" the typename
        invariant(
          !hadTypename || hasTypename,
          `Store error: the application attempted to write an object with no provided typename but the store already contains an object with typename of ${
            escapedId.typename
          } for the object of id ${escapedId.id}. The selectionSet that was trying to be written is:\n${
            JSON.stringify(field)
          }`,
github apollographql / apollo-client / packages / apollo-cache-inmemory / src / writeToStore.ts View on Github external
let generated = true;

      // We only prepend the '$' if the valueDataId isn't already a generated
      // id.
      if (!isGeneratedId(valueDataId)) {
        valueDataId = '$' + valueDataId;
      }

      if (dataIdFromObject) {
        const semanticId = dataIdFromObject(value);

        // We throw an error if the first character of the id is '$. This is
        // because we use that character to designate an Apollo-generated id
        // and we use the distinction between user-desiginated and application-provided
        // ids when managing overwrites.
        invariant(
          !semanticId || !isGeneratedId(semanticId),
          'IDs returned by dataIdFromObject cannot begin with the "$" character.',
        );

        if (
          semanticId ||
          (typeof semanticId === 'number' && semanticId === 0)
        ) {
          valueDataId = semanticId;
          generated = false;
        }
      }

      if (!isDataProcessed(valueDataId, field, context.processedData)) {
        this.writeSelectionSetToStore({
          dataId: valueDataId,
github caioreis123 / market2 / backend2 / node_modules / apollo-utilities / lib / bundle.cjs.js View on Github external
function getFragmentDefinition(doc) {
    process.env.NODE_ENV === "production" ? tsInvariant.invariant(doc.kind === 'Document') : tsInvariant.invariant(doc.kind === 'Document', "Expecting a parsed GraphQL document. Perhaps you need to wrap the query string in a \"gql\" tag? http://docs.apollostack.com/apollo-client/core.html#gql");
    process.env.NODE_ENV === "production" ? tsInvariant.invariant(doc.definitions.length <= 1) : tsInvariant.invariant(doc.definitions.length <= 1, 'Fragment must have exactly one definition.');
    var fragmentDef = doc.definitions[0];
    process.env.NODE_ENV === "production" ? tsInvariant.invariant(fragmentDef.kind === 'FragmentDefinition') : tsInvariant.invariant(fragmentDef.kind === 'FragmentDefinition', 'Must be a fragment definition.');
    return fragmentDef;
}
function getMainDefinition(queryDoc) {
github caioreis123 / market2 / backend2 / node_modules / apollo-utilities / lib / bundle.esm.js View on Github external
function getOperationDefinitionOrDie(document) {
    var def = getOperationDefinition(document);
    process.env.NODE_ENV === "production" ? invariant(def) : invariant(def, "GraphQL document is missing an operation");
    return def;
}
function getOperationName(doc) {
github caioreis123 / market2 / backend2 / node_modules / apollo-utilities / lib / bundle.cjs.js View on Github external
function getMutationDefinition(doc) {
    checkDocument(doc);
    var mutationDef = doc.definitions.filter(function (definition) {
        return definition.kind === 'OperationDefinition' &&
            definition.operation === 'mutation';
    })[0];
    process.env.NODE_ENV === "production" ? tsInvariant.invariant(mutationDef) : tsInvariant.invariant(mutationDef, 'Must contain a mutation definition.');
    return mutationDef;
}
function checkDocument(doc) {
github caioreis123 / market2 / backend2 / node_modules / apollo-utilities / lib / bundle.esm.js View on Github external
function checkDocument(doc) {
    process.env.NODE_ENV === "production" ? invariant(doc && doc.kind === 'Document') : invariant(doc && doc.kind === 'Document', "Expecting a parsed GraphQL document. Perhaps you need to wrap the query string in a \"gql\" tag? http://docs.apollostack.com/apollo-client/core.html#gql");
    var operations = doc.definitions
        .filter(function (d) { return d.kind !== 'FragmentDefinition'; })
        .map(function (definition) {
        if (definition.kind !== 'OperationDefinition') {
            throw process.env.NODE_ENV === "production" ? new InvariantError() : new InvariantError("Schema type definitions not allowed in queries. Found: \"" + definition.kind + "\"");
        }
        return definition;
    });
    process.env.NODE_ENV === "production" ? invariant(operations.length <= 1) : invariant(operations.length <= 1, "Ambiguous GraphQL document: contains " + operations.length + " operations");
    return doc;
}
function getOperationDefinition(doc) {
github caioreis123 / market2 / backend2 / node_modules / apollo-utilities / lib / bundle.esm.js View on Github external
function checkDocument(doc) {
    process.env.NODE_ENV === "production" ? invariant(doc && doc.kind === 'Document') : invariant(doc && doc.kind === 'Document', "Expecting a parsed GraphQL document. Perhaps you need to wrap the query string in a \"gql\" tag? http://docs.apollostack.com/apollo-client/core.html#gql");
    var operations = doc.definitions
        .filter(function (d) { return d.kind !== 'FragmentDefinition'; })
        .map(function (definition) {
        if (definition.kind !== 'OperationDefinition') {
            throw process.env.NODE_ENV === "production" ? new InvariantError() : new InvariantError("Schema type definitions not allowed in queries. Found: \"" + definition.kind + "\"");
        }
        return definition;
    });
    process.env.NODE_ENV === "production" ? invariant(operations.length <= 1) : invariant(operations.length <= 1, "Ambiguous GraphQL document: contains " + operations.length + " operations");
    return doc;
}
function getOperationDefinition(doc) {
github apollographql / apollo-client / packages / apollo-client / src / ApolloClient.ts View on Github external
public query(
    options: QueryOptions,
  ): Promise> {
    if (this.defaultOptions.query) {
      options = { ...this.defaultOptions.query, ...options } as QueryOptions<
        TVariables
      >;
    }

    invariant(
      (options.fetchPolicy as WatchQueryFetchPolicy) !== 'cache-and-network',
      'The cache-and-network fetchPolicy does not work with client.query, because ' +
      'client.query can only return a single result. Please use client.watchQuery ' +
      'to receive multiple results from the cache and the network, or consider ' +
      'using a different fetchPolicy, such as cache-first or network-only.'
    );

    if (this.disableNetworkFetches && options.fetchPolicy === 'network-only') {
      options = { ...options, fetchPolicy: 'cache-first' };
    }

    return this.queryManager.query(options);
  }

ts-invariant

TypeScript implementation of invariant(condition, message)

MIT
Latest version published 3 years ago

Package Health Score

73 / 100
Full package analysis