How to use the graphql-transformer-common.makeInputValueDefinition 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-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-key-transformer / src / KeyTransformer.ts View on Github external
if (listResolverResource && this.isPrimaryKey(directive)) {
            // By default takes a single argument named 'id'. Replace it with the updated primary key structure.
            let query = ctx.getQuery();
            let listField: FieldDefinitionNode = query.fields.find(field => field.name.value === listResolverResource.Properties.FieldName) as FieldDefinitionNode;
            let listArguments: InputValueDefinitionNode[] = [ ...listField.arguments ];
            const args: KeyArguments = getDirectiveArguments(directive);
            if (args.fields.length > 2) {
                listArguments = addCompositeSortKey(definition, args, listArguments);
                listArguments = addHashField(definition, args, listArguments);
            } else if (args.fields.length === 2) {
                listArguments = addSimpleSortKey(ctx, definition, args, listArguments);
                listArguments = addHashField(definition, args, listArguments);
            } else {
                listArguments = addHashField(definition, args, listArguments);
            }
            listArguments.push(makeInputValueDefinition('sortDirection', makeNamedType('ModelSortDirection')));
            listField = { ...listField, arguments: listArguments };
            query = { ...query, fields: query.fields.map(field => field.name.value === listField.name.value ? listField : field)}
            ctx.putType(query);
        }
    }
github aws-amplify / amplify-cli / packages / graphql-dynamodb-transformer / src / DynamoDBModelTransformer.ts View on Github external
if (!this.typeExist('ModelSortDirection', ctx)) {
                const tableSortDirection = makeModelSortDirectionEnumObject()
                ctx.addEnum(tableSortDirection)
            }
        }

        // Create get queries
        if (shouldMakeGet) {
            const getResolver = this.resources.makeGetResolver(def.name.value, getFieldNameOverride, ctx.getQueryTypeName())
            const resourceId = ResolverResourceIDs.DynamoDBGetResolverResourceID(typeName);
            ctx.setResource(resourceId, getResolver);
            ctx.mapResourceToStack(typeName, resourceId);

            queryFields.push(makeField(
                getResolver.Properties.FieldName,
                [makeInputValueDefinition('id', makeNonNullType(makeNamedType('ID')))],
                makeNamedType(def.name.value)
            ))
        }

        if (shouldMakeList) {

            this.generateModelXConnectionType(ctx, def)

            // Create the list resolver
            const listResolver = this.resources.makeListResolver(def.name.value, listFieldNameOverride, ctx.getQueryTypeName())
            const resourceId = ResolverResourceIDs.DynamoDBListResolverResourceID(typeName);
            ctx.setResource(resourceId, listResolver);
            ctx.mapResourceToStack(typeName, resourceId);

            queryFields.push(makeConnectionField(listResolver.Properties.FieldName, def.name.value))
        }
github aws-amplify / amplify-cli / packages / graphql-key-transformer / src / KeyTransformer.ts View on Github external
function addCompositeSortKey(definition: ObjectTypeDefinitionNode, args: KeyArguments, elems: InputValueDefinitionNode[]): InputValueDefinitionNode[] {
    let sortKeyNames = args.fields.slice(1);
    const compositeSortKeyName = toCamelCase(sortKeyNames);
    const hashKey = makeInputValueDefinition(compositeSortKeyName, makeNamedType(ModelResourceIDs.ModelCompositeKeyConditionInputTypeName(definition.name.value, args.name || 'Primary')));
    return [hashKey, ...elems];
}
function joinSnippets(lines: string[]): string {
github aws-amplify / amplify-cli / packages / graphql-key-transformer / src / KeyTransformer.ts View on Github external
return keyFields.map(keyFieldName => {
        const keyField: FieldDefinitionNode = definition.fields.find(field => field.name.value === keyFieldName);
        return makeInputValueDefinition(keyFieldName, makeNonNullType(makeNamedType(getBaseType(keyField.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-dynamodb-transformer / src / DynamoDBModelTransformer.ts View on Github external
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)))],
                makeNamedType(def.name.value)
            ));
        }
        ctx.addMutationFields(mutationFields)
    }
github aws-amplify / amplify-cli / packages / graphql-elasticsearch-transformer / src / SearchableModelTransformer.ts View on Github external
const searchResolver = this.resources.makeSearchResolver(
        def.name.value,
        nonKeywordFields,
        primaryKey,
        ctx.getQueryTypeName(),
        searchFieldNameOverride
      );
      ctx.setResource(ResolverResourceIDs.ElasticsearchSearchResolverResourceID(def.name.value), searchResolver);
      ctx.mapResourceToStack(STACK_NAME, ResolverResourceIDs.ElasticsearchSearchResolverResourceID(def.name.value));
      queryFields.push(
        makeField(
          searchResolver.Properties.FieldName.toString(),
          [
            makeInputValueDefinition('filter', makeNamedType(`Searchable${def.name.value}FilterInput`)),
            makeInputValueDefinition('sort', makeNamedType(`Searchable${def.name.value}SortInput`)),
            makeInputValueDefinition('limit', makeNamedType('Int')),
            makeInputValueDefinition('nextToken', makeNamedType('String')),
          ],
          makeNamedType(`Searchable${def.name.value}Connection`)
        )
      );
    }

    ctx.addQueryFields(queryFields);
  };