Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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]
)
);
}
}
};
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]
)
);
}
}
};
});
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]));
}
}
}
};
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]));
}
}
}
};
});
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]));
}
}
}
};
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')
}
}