How to use the graphql-transformer-common.makeNonNullType function in graphql-transformer-common

To help you get started, we’ve selected a few graphql-transformer-common 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 aws-amplify / amplify-cli / packages / graphql-versioned-transformer / src / VersionedModelTransformer.ts View on Github external
if (versionFieldImpl) {
        const baseType = getBaseType(versionFieldImpl.type);
        if (baseType === 'Int' || baseType === 'BigInt') {
          // ok.
          if (versionFieldImpl.type.kind !== Kind.NON_NULL_TYPE) {
            updatedField = {
              ...updatedField,
              type: makeNonNullType(versionFieldImpl.type),
            };
            updatedFields = updatedFields.map(f => (f.name.value === versionField ? updatedField : f));
          }
        } else {
          throw new TransformerContractError(`The versionField "${versionField}" is required to be of type "Int" or "BigInt".`);
        }
      } else {
        updatedField = makeField(versionField, [], makeNonNullType(makeNamedType('Int')));
        updatedFields = [...updatedFields, updatedField];
      }
      const updatedType = {
        ...type,
        fields: updatedFields,
      };
      ctx.putType(updatedType);
    }
  }
}
github aws-amplify / amplify-cli / packages / graphql-connection-transformer / src / definitions.ts View on Github external
export function updateCreateInputWithConnectionField(
  input: InputObjectTypeDefinitionNode,
  connectionFieldName: string,
  nonNull: boolean = false
): InputObjectTypeDefinitionNode {
  const keyFieldExists = Boolean(input.fields.find(f => f.name.value === connectionFieldName));
  // If the key field already exists then do not change the input.
  // The @connection field will validate that the key field is valid.
  if (keyFieldExists) {
    return input;
  }
  const updatedFields = [
    ...input.fields,
    makeInputValueDefinition(connectionFieldName, nonNull ? makeNonNullType(makeNamedType('ID')) : makeNamedType('ID')),
  ];
  return {
    ...input,
    fields: updatedFields,
  };
}
github aws-amplify / amplify-cli / packages / graphql-versioned-transformer / src / VersionedModelTransformer.ts View on Github external
private enforceVersionedFieldOnType(ctx: TransformerContext, typeName: string, versionField: string) {
    const type = ctx.getType(typeName);
    if (type && type.kind === Kind.OBJECT_TYPE_DEFINITION) {
      let updatedFields = type.fields;
      const versionFieldImpl = type.fields.find(f => f.name.value === versionField);
      let updatedField = versionFieldImpl;
      if (versionFieldImpl) {
        const baseType = getBaseType(versionFieldImpl.type);
        if (baseType === 'Int' || baseType === 'BigInt') {
          // ok.
          if (versionFieldImpl.type.kind !== Kind.NON_NULL_TYPE) {
            updatedField = {
              ...updatedField,
              type: makeNonNullType(versionFieldImpl.type),
            };
            updatedFields = updatedFields.map(f => (f.name.value === versionField ? updatedField : f));
          }
        } else {
          throw new TransformerContractError(`The versionField "${versionField}" is required to be of type "Int" or "BigInt".`);
        }
      } else {
        updatedField = makeField(versionField, [], makeNonNullType(makeNamedType('Int')));
        updatedFields = [...updatedFields, updatedField];
      }
      const updatedType = {
        ...type,
        fields: updatedFields,
      };
      ctx.putType(updatedType);
    }
github aws-amplify / amplify-cli / packages / graphql-key-transformer / src / KeyTransformer.ts View on Github external
fields: input.fields.reduce((acc, f) => {
            // If the field is a key, make it non-null.
            if (keyFields.find(k => k === f.name.value)) {
                return [...acc, makeInputValueDefinition(f.name.value, makeNonNullType(makeNamedType(getBaseType(f.type))))];
            }
            return [...acc, f];
        }, [])
    };
github aws-amplify / amplify-cli / packages / graphql-http-transformer / src / definitions.ts View on Github external
export function makeHttpArgument(name: string, inputType: InputObjectTypeDefinitionNode, makeNonNull: boolean): InputValueDefinitionNode {
  // the URL params type that we create will need to be non-null, so build in some flexibility here
  const type = makeNonNull ? makeNonNullType(makeNamedType(inputType.name.value)) : makeNamedType(inputType.name.value);
  return makeInputValueDefinition(name, type);
}
github aws-amplify / amplify-cli / packages / graphql-auth-transformer / src / ModelAuthTransformer.ts View on Github external
private addSubscriptionOwnerArgument(ctx: TransformerContext, resolver: Resolver, makeNonNull: boolean = false) {
        let subscription = ctx.getSubscription();
        let createField: FieldDefinitionNode = subscription.fields.find(
            field => field.name.value === resolver.Properties.FieldName,
            ) as FieldDefinitionNode;
        const nameNode: any = makeNonNull ? makeNonNullType(makeNamedType('String')) : makeNamedType('String');
        const createArguments = [makeInputValueDefinition(DEFAULT_OWNER_FIELD, nameNode)];
        createField = {
            ...createField,
            arguments: createArguments,
        };
        subscription = {
            ...subscription,
            fields: subscription.fields.map(
                field => field.name.value === resolver.Properties.FieldName ? createField : field,
            ),
        };
        ctx.putType(subscription);
    }
github aws-amplify / amplify-cli / packages / graphql-versioned-transformer / src / VersionedModelTransformer.ts View on Github external
private addVersionedInputToInput(ctx: TransformerContext, inputName: string, versionInput: string) {
    const input = ctx.getType(inputName);
    if (input && input.kind === Kind.INPUT_OBJECT_TYPE_DEFINITION) {
      const updatedFields = [...input.fields, makeInputValueDefinition(versionInput, makeNonNullType(makeNamedType('Int')))];
      const updatedInput = {
        ...input,
        fields: updatedFields,
      };
      ctx.putType(updatedInput);
    }
  }
github aws-amplify / amplify-cli / packages / graphql-dynamodb-transformer / src / DynamoDBModelTransformer.ts View on Github external
makeNamedType(def.name.value)
            ));
        }

        if (shouldMakeUpdate) {
            const updateInput = makeUpdateInputObject(def, nonModelArray, ctx)
            if (!ctx.getType(updateInput.name.value)) {
                ctx.addInput(updateInput)
            }
            const updateResolver = this.resources.makeUpdateResolver(def.name.value, updateFieldNameOverride)
            const resourceId = ResolverResourceIDs.DynamoDBUpdateResolverResourceID(typeName);
            ctx.setResource(resourceId, updateResolver);
            ctx.mapResourceToStack(typeName, resourceId);
            mutationFields.push(makeField(
                updateResolver.Properties.FieldName,
                [makeInputValueDefinition('input', makeNonNullType(makeNamedType(updateInput.name.value)))],
                makeNamedType(def.name.value)
            ));
        }

        if (shouldMakeDelete) {
            const deleteInput = makeDeleteInputObject(def)
            if (!ctx.getType(deleteInput.name.value)) {
                ctx.addInput(deleteInput)
            }
            const deleteResolver = this.resources.makeDeleteResolver(def.name.value, deleteFieldNameOverride)
            const resourceId = ResolverResourceIDs.DynamoDBDeleteResolverResourceID(typeName);
            ctx.setResource(resourceId, deleteResolver);
            ctx.mapResourceToStack(typeName, resourceId);
            mutationFields.push(makeField(
                deleteResolver.Properties.FieldName,
                [makeInputValueDefinition('input', makeNonNullType(makeNamedType(deleteInput.name.value)))],