Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
console.warn(`Couldn't create foreign field ${foreignKey} on type ${fieldType.name} on field ${field.name}. See above messages.`)
return null
}
type = descriptor.type
args = descriptor.args
foreign = {
type: foreignType.name,
field: foreignField.name,
tableName: null,
columnName: null,
}
// List
} else if (isListType(fieldType) && this.currentTable) {
let ofType = fieldType.ofType
ofType = isNonNullType(ofType) ? ofType.ofType : ofType
if (isObjectType(ofType)) {
// Foreign Type
const onSameType = this.currentType === ofType.name
const foreignType = this.typeMap[ofType.name]
if (!foreignType) {
console.warn(`Foreign type ${ofType.name} not found on field ${this.currentType}.${field.name}.`)
return null
}
if (!isObjectType(foreignType)) {
console.warn(`Foreign type ${ofType.name} is not Object type on field ${this.currentType}.${field.name}.`)
return null
}
// Foreign Field
const foreignKey = onSameType ? field.name : annotations.manyToMany || this.currentTable.name
const foreignField = foreignType.getFields()[foreignKey]
private getFieldDescriptor(
field: GraphQLField,
fieldType: GraphQLOutputType | null = null,
): TableColumn | null {
const annotations: any = parseAnnotations('db', field.description || null)
if (annotations.skip) {
return null
}
if (!fieldType) {
fieldType = isNonNullType(field.type) ? field.type.ofType : field.type
}
const notNull = isNonNullType(field.type)
let columnName: string = annotations.name || this.getColumnName(field.name)
let type: string
let args: any[]
let foreign: ForeignKey | null = null
if (columnName === 'id' && (isScalarType(fieldType) && fieldType.name !== 'ID')) {
throw new Error(`Scalar ID is missing on type ${this.currentType}.${field.name}`);
}
// Scalar
if (isScalarType(fieldType) || annotations.type) {
let descriptor
if (this.scalarMap) {
descriptor = this.scalarMap(field, isScalarType(fieldType) ? fieldType : null, annotations)
}
if (!descriptor) {
function unwrap(
type: GraphQLOutputType,
nullable: boolean
): GraphQLOutputType {
if (isNonNullType(type)) {
return unwrap(type.ofType, false)
}
if (nullable) {
addModifier('Nullable')
}
if (isListType(type)) {
addModifier('ReadonlyArray')
return unwrap(type.ofType, true)
}
if (isScalarType(type) || isEnumType(type) || isObjectType(type))
return type
throw 'unhandled GraphQLOutputType in unwrap'
export function safeChangeForInputValue(
oldType: GraphQLInputType,
newType: GraphQLInputType,
): boolean {
if (!isWrappingType(oldType) && !isWrappingType(newType)) {
return oldType.toString() === newType.toString();
}
if (isListType(oldType) && isListType(newType)) {
return safeChangeForInputValue(oldType.ofType, newType.ofType);
}
if (isNonNullType(oldType)) {
const ofType = isNonNullType(newType) ? newType : newType;
return safeChangeForInputValue(oldType.ofType, ofType);
}
return false;
}
function innerType(type: GraphQLInputType): GraphQLInputType & GraphQLNamedType {
if (isNonNullType(type) || isListType(type)) {
return innerType(type.ofType);
}
return type;
}
function validateValueAgainstType(
value: any,
type: GraphQLType,
keyPath: KeyPath,
options: TypeValidationOptions = {shallow: false},
): Error[] {
const {shallow} = options;
if (isNonNullType(type)) {
return value == null
? [error(keyPath, `should be non-null but was ${String(value)}`)]
: validateValueAgainstType(value, type.ofType, keyPath, options);
}
if (value === null) {
return [];
}
const valueType = typeof value;
if (isListType(type)) {
if (!Array.isArray(value)) {
return [
error(
keyPath,
export function isListTypeIgnoringNonNull(type: QueryNodeOutputType): boolean {
if (isNonNullType(type) || type instanceof QueryNodeNonNullType) {
return isListTypeIgnoringNonNull(type.ofType);
}
return isListType(type) || type instanceof QueryNodeListType;
}
export function propertyFromInputField(
context: LegacyCompilerContext,
field: GraphQLInputField,
namespace?: string,
parentTraitName?: string
): GraphQLInputField & Property {
const name = field.name;
const unescapedPropertyName = isMetaFieldName(name) ? name : camelCase(name);
const propertyName = escapeIdentifierIfNeeded(unescapedPropertyName);
const type = field.type;
const isList = isListType(type);
const isOptional = !isNonNullType(type);
const bareType = getNamedType(type);
const bareTypeName = isCompositeType(bareType)
? join(
[
namespace,
parentTraitName,
escapeIdentifierIfNeeded(pascalCase(Inflector.singularize(name)))
],
"."
)
: undefined;
const typeName = typeNameFromGraphQLType(
context,
type,
bareTypeName,
function isRequiredArgument(arg: GraphQLArgument): boolean %checks {
return isNonNullType(arg.type) && arg.defaultValue === undefined;
}
function handleInputType(node) {
if (graphql_1.isNonNullType(node)) {
handleInputType(node.ofType);
return;
}
if (graphql_1.isListType(node)) {
handleInputType(node.ofType);
return;
}
if (graphql_1.isInputObjectType(node)) {
if (!inputTypeNames[node.name]) {
inputTypeNames[node.name] = true;
newNames2.push(node.name);
}
return;
}
}
}