react-apollo-testing-mock-gen
Version:
Mock generator for testing with MockedProvider.
34 lines (25 loc) • 922 B
JavaScript
const config = require('../config');
const isListTypeDefiniton = (type, isList = false) => {
let isListType = isList;
if (isListType) {
return isListType;
}
if (type && type.kind) {
isListType = type.kind === 'ListType';
} else if (!type || !type.type || !type.kind) {
return isListType;
}
return isListTypeDefiniton(type.type, isListType);
};
const isScalarTypeDefinition = (typename) => Object.keys(config.resolvers.ScalarTypeDefinition).includes(typename);
const isPrimitiveTypeDefinition = (typename) => Object.keys(config.resolvers).includes(typename);
const isTypedDefinition = (definition, operationType) => {
return (definition.kind === 'ObjectTypeDefinition' || definition.kind === 'InterfaceTypeDefinition') &&
definition.name.value === operationType;
};
module.exports = {
isListTypeDefiniton,
isScalarTypeDefinition,
isPrimitiveTypeDefinition,
isTypedDefinition
}