Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default function isRequired(typeObj: GraphQLType): boolean {
if (isNonNullType(typeObj) && isListType(typeObj.ofType)) {
// See if it's a Non-null List of Non-null Types
return isRequired(typeObj.ofType.ofType);
}
if (isListType(typeObj)) {
// See if it's a Nullable List of Non-null Types
return isNonNullType(typeObj.ofType);
}
return isNonNullType(typeObj);
}
const childInlineFragments: { onType: string; node: InlineFragmentNode }[] = [];
const childFragmentSpread: LoadedFragment[] = [...(options.additionalFragments || [])];
const selections = [...(options.selectionSet || [])];
const responseFieldArr: string[] = [];
for (const selection of selections) {
if (selection.kind === Kind.FIELD) {
this._imports.add(Imports.ResponseField);
const field = fields[selection.name.value];
const isObject = selection.selectionSet && selection.selectionSet.selections && selection.selectionSet.selections.length > 0;
const isNonNull = isNonNullType(field.type);
const fieldAnnotation = isNonNull ? 'Nonnull' : 'Nullable';
this._imports.add(Imports[fieldAnnotation]);
const baseType = getBaseType(field.type);
const isList = isListType(field.type) || (isNonNullType(field.type) && isListType(field.type.ofType));
if (isObject) {
let childClsName = this.convertName(field.name);
if (isList && isPlural(childClsName)) {
childClsName = singular(childClsName);
}
this.transformSelectionSet(
{
className: childClsName,
result: options.result,
selectionSet: selection.selectionSet.selections,
schemaType: baseType as GraphQLObjectType,
},
false
export const typeIsList = (type) => {
let isList = false;
if (type.name && type.name.endsWith('Connection')) {
isList = true;
}
while (!isList && (isListType(type) || isNonNullType(type) || type.kind === 'NON_NULL' || type.kind === 'LIST')) {
if (isListType(type) || type.kind === 'LIST') {
isList = true;
break;
}
type = type.ofType;
}
return isList;
};
export const getReturnType = (type) => {
export const generateFieldsForInput = (fieldName, inputTypes, defaultValue) => {
const fields = {};
fields[fieldName] = {
type: inputTypes[0],
defaultValue: defaultValue
};
if (inputTypes[1] && !isScalarType(getReturnGraphQLType(inputTypes[0]))) {
const idName = isListType(inputTypes[1]) ? fieldName + 'Ids' : fieldName + 'Id';
fields[idName] = {
type: inputTypes[1]
};
}
return fields;
};
export const stripNonNull = (type) => {
export function resolveFieldType(
type: GraphQLOutputType | GraphQLNamedType
): any {
if (isNonNullType(type)) {
return resolveFieldType(type.ofType);
}
if (isListType(type)) {
return {
type: 'array',
items: resolveFieldType(type.ofType),
};
}
if (isObjectType(type)) {
return {
$ref: mapToRef(type.name),
};
}
if (isScalarType(type)) {
return (
mapToPrimitive(type.name) || {
type: 'object',
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 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;
}
}
}
function nonNullableTypeFromGraphQLType(
graphQLType: GraphQLType,
typeName?: string
): t.TSType {
if (isListType(graphQLType)) {
const elementType = typeFromGraphQLType(graphQLType.ofType, typeName);
return ArrayType(
t.isTSUnionType(elementType)
? t.TSParenthesizedType(elementType)
: elementType
);
} else if (isScalarType(graphQLType)) {
const builtIn = builtInScalarMap[typeName || graphQLType.name];
if (builtIn != null) {
return builtIn;
} else if (compilerOptions.passthroughCustomScalars) {
return t.TSTypeReference(
t.identifier(
(compilerOptions.customScalarsPrefix || "") + graphQLType.name
)
);
function rootType(type: GraphQLType) {
let finalType = type;
while (isNonNullType(finalType) || isListType(finalType)) {
finalType = finalType.ofType;
}
return finalType;
}