How to use graphql-schema-linter - 6 common examples

To help you get started, we’ve selected a few graphql-schema-linter 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 reactioncommerce / reaction / .reaction / graphql-linter / rules / type_fields_sorted_alphabetically.js View on Github external
ObjectTypeDefinition: function ObjectTypeDefinition(node) {
      const fieldList = (node.fields || []).map((field) => field.name.value);
      const { isSorted, sortedList } = listIsAlphabetical(fieldList);

      if (!isSorted) {
        context.reportError(
          new _validation_error.ValidationError(
            "type-fields-sorted-alphabetically",
            "The fields of object type `" +
              node.name.value +
              "` must be sorted alphabetically." +
              " Expected sorting: " +
              sortedList.join(", "),
            [node]
          )
        );
      }
    }
  };
github reactioncommerce / reaction / .reaction / graphql-linter / rules / input_object_fields_sorted_alphabetically.js View on Github external
InputObjectTypeDefinition: function InputObjectTypeDefinition(node) {
      const fieldList = (node.fields || []).map((field) => field.name.value);
      const { isSorted, sortedList } = listIsAlphabetical(fieldList);

      if (!isSorted) {
        context.reportError(
          new _validation_error.ValidationError(
            "input-object-fields-sorted-alphabetically",
            "The fields of input type `" +
              node.name.value +
              "` must be sorted alphabetically." +
              " Expected sorting: " +
              sortedList.join(", "),
            [node]
          )
        );
      }
    }
  };
github reactioncommerce / reaction / .reaction / graphql-linter / rules / relay_connection_arguments_spec_custom.js View on Github external
});
      var hasBackwardPagination = lastArgument && beforeArgument;

      if (!hasForwardPagination && !hasBackwardPagination) {
        return context.reportError(new _validation_error.ValidationError('relay-connection-arguments-spec-custom', 'A field that returns a Connection Type must include forward pagination arguments (`first` and `after`), backward pagination arguments (`last` and `before`), or both as per the Relay spec.', [node]));
      }

      if (firstArgument) {
        if (firstArgument.type.kind != 'NamedType' || (firstArgument.type.name.value != 'Int' && firstArgument.type.name.value != 'ConnectionLimitInt')) {
          return context.reportError(new _validation_error.ValidationError('relay-connection-arguments-spec-custom', 'Fields that support forward pagination must include a `first` argument that takes a non-negative integer as per the Relay spec.', [firstArgument]));
        }
      }

      if (lastArgument) {
        if (lastArgument.type.kind != 'NamedType' || (lastArgument.type.name.value != 'Int' && lastArgument.type.name.value != 'ConnectionLimitInt')) {
          return context.reportError(new _validation_error.ValidationError('relay-connection-arguments-spec-custom', 'Fields that support forward pagination must include a `last` argument that takes a non-negative integer as per the Relay spec.', [lastArgument]));
        }
      }
    }
  };
github reactioncommerce / reaction / .reaction / graphql-linter / rules / relay_connection_arguments_spec_custom.js View on Github external
var lastArgument = node.arguments.find(function (argument) {
        return argument.name.value == 'last';
      });
      var beforeArgument = node.arguments.find(function (argument) {
        return argument.name.value == 'before';
      });
      var hasBackwardPagination = lastArgument && beforeArgument;

      if (!hasForwardPagination && !hasBackwardPagination) {
        return context.reportError(new _validation_error.ValidationError('relay-connection-arguments-spec-custom', 'A field that returns a Connection Type must include forward pagination arguments (`first` and `after`), backward pagination arguments (`last` and `before`), or both as per the Relay spec.', [node]));
      }

      if (firstArgument) {
        if (firstArgument.type.kind != 'NamedType' || (firstArgument.type.name.value != 'Int' && firstArgument.type.name.value != 'ConnectionLimitInt')) {
          return context.reportError(new _validation_error.ValidationError('relay-connection-arguments-spec-custom', 'Fields that support forward pagination must include a `first` argument that takes a non-negative integer as per the Relay spec.', [firstArgument]));
        }
      }

      if (lastArgument) {
        if (lastArgument.type.kind != 'NamedType' || (lastArgument.type.name.value != 'Int' && lastArgument.type.name.value != 'ConnectionLimitInt')) {
          return context.reportError(new _validation_error.ValidationError('relay-connection-arguments-spec-custom', 'Fields that support forward pagination must include a `last` argument that takes a non-negative integer as per the Relay spec.', [lastArgument]));
        }
      }
    }
  };
github reactioncommerce / reaction / .reaction / graphql-linter / rules / relay_connection_arguments_spec_custom.js View on Github external
});
      var afterArgument = node.arguments.find(function (argument) {
        return argument.name.value == 'after';
      });
      var hasForwardPagination = firstArgument && afterArgument;

      var lastArgument = node.arguments.find(function (argument) {
        return argument.name.value == 'last';
      });
      var beforeArgument = node.arguments.find(function (argument) {
        return argument.name.value == 'before';
      });
      var hasBackwardPagination = lastArgument && beforeArgument;

      if (!hasForwardPagination && !hasBackwardPagination) {
        return context.reportError(new _validation_error.ValidationError('relay-connection-arguments-spec-custom', 'A field that returns a Connection Type must include forward pagination arguments (`first` and `after`), backward pagination arguments (`last` and `before`), or both as per the Relay spec.', [node]));
      }

      if (firstArgument) {
        if (firstArgument.type.kind != 'NamedType' || (firstArgument.type.name.value != 'Int' && firstArgument.type.name.value != 'ConnectionLimitInt')) {
          return context.reportError(new _validation_error.ValidationError('relay-connection-arguments-spec-custom', 'Fields that support forward pagination must include a `first` argument that takes a non-negative integer as per the Relay spec.', [firstArgument]));
        }
      }

      if (lastArgument) {
        if (lastArgument.type.kind != 'NamedType' || (lastArgument.type.name.value != 'Int' && lastArgument.type.name.value != 'ConnectionLimitInt')) {
          return context.reportError(new _validation_error.ValidationError('relay-connection-arguments-spec-custom', 'Fields that support forward pagination must include a `last` argument that takes a non-negative integer as per the Relay spec.', [lastArgument]));
        }
      }
    }
  };
github Urigo / graphql-cli / src / cmds / lint.ts View on Github external
export async function handler(context: Context) {
  const { schemaPath } = await context.getProjectConfig()

  const exitCode = runner.run(process.stdout, process.stdin, process.stderr, [
    '',
    '',
    schemaPath,
  ])

  if (exitCode !== 0) {
    throw new Error('Linting errors were found')
  }
}

graphql-schema-linter

Command line tool and package to validate GraphQL schemas against a set of rules.

MIT
Latest version published 2 years ago

Package Health Score

53 / 100
Full package analysis

Similar packages