How to use graphql-transformer-common - 10 common examples

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-transformers-e2e-tests / src / CloudFormationClient.ts View on Github external
async createStack(template: any, name: string, defParams: any = {}, addAppSyncApiName: boolean = true) {
    const params = [];

    if (addAppSyncApiName === true) {
      params.push({
        ParameterKey: ResourceConstants.PARAMETERS.AppSyncApiName,
        ParameterValue: name,
      });
    }

    for (const key of Object.keys(defParams)) {
      params.push({
        ParameterKey: key,
        ParameterValue: defParams[key],
      });
    }

    // add env info to template
    template.Parameters.env = {
      Type: 'String',
      Description: 'env name',
      Default: 'NONE',
github aws-amplify / amplify-cli / packages / graphql-transformer-core / src / util / amplifyUtils.ts View on Github external
const parametersForStack = Object.keys(userDefinedStack.Parameters).reduce(
      (acc, k) => ({
        ...acc,
        [k]: customStackParams[k],
      }),
      {}
    );

    transformStacks[userStack] = userDefinedStack;
    // Split on non alphabetic characters to make a valid resource id.
    const stackResourceId = userStack.split(/[^A-Za-z]/).join('');
    const customNestedStack = new CloudFormation.Stack({
      Parameters: parametersForStack,
      TemplateURL: Fn.Join('/', [
        'https://s3.amazonaws.com',
        Fn.Ref(ResourceConstants.PARAMETERS.S3DeploymentBucket),
        Fn.Ref(ResourceConstants.PARAMETERS.S3DeploymentRootKey),
        'stacks',
        userStack,
      ]),
    }).dependsOn(allResourceIds);
    rootStack.Resources[stackResourceId] = customNestedStack;
  }

  // Update the Root Stack Params since we have added the Child Stack Params if they are missing.
  rootStack.Parameters = updatedParameters;
  return {
    ...transformOutput,
    resolvers: transformResolvers,
    stacks: transformStacks,
  };
}
github aws-amplify / amplify-cli / packages / graphql-connection-transformer / src / ModelConnectionTransformer.ts View on Github external
throw new InvalidDirectiveError(inputFieldNames[0] + ' field is not of type ' + getBaseType(tablePKType))
    }
    if (numFields > keySchema.length && keySchema.length !== 2) {
        throw new InvalidDirectiveError('Too many fields passed in to @connection directive.')
    }
    if (numFields === 2) {
        const sortAttributeName = keySchema[1].AttributeName;
        const tableSKType = relatedTypeFields.find(f => f.name.value === sortAttributeName).type;
        const querySKType = parentFields.find(f => f.name.value === inputFieldNames[1]).type;

        if (getBaseType(tableSKType) !== getBaseType(querySKType)) {
            throw new InvalidDirectiveError(inputFieldNames[1] + ' field is not of type ' + getBaseType(tableSKType))
        }

    } else if (numFields > 2) {
        const tableSortFields = keySchema[1].AttributeName.split(ModelResourceIDs.ModelCompositeKeySeparator());
        const tableSortKeyTypes = tableSortFields.map(name => relatedTypeFields.find(f => f.name.value === name).type);
        const querySortFields = inputFieldNames.slice(1);
        const querySortKeyTypes = querySortFields.map(name => parentFields.find(f => f.name.value === name).type);

        // Check that types of each attribute match types of the fields that make up the composite sort key for the
        // table or index being queried.
        querySortKeyTypes.forEach((fieldType, index) => {
            if (getBaseType(fieldType) !== getBaseType(tableSortKeyTypes[index])) {
                throw new InvalidDirectiveError(
                            querySortFields[index] + ' field is not of type ' + getBaseType(tableSortKeyTypes[index])
                )
            }
        })
    }
}
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-dynamodb-transformer / src / definitions.ts View on Github external
if (functions.has('attributeExists')) {
    fields.push({
      kind: Kind.INPUT_VALUE_DEFINITION,
      name: { kind: 'Name' as 'Name', value: 'attributeExists' },
      type: makeNamedType('Boolean'),
      // TODO: Service does not support new style descriptions so wait.
      // description: field.description,
      directives: [],
    });
  }

  if (functions.has('attributeType')) {
    fields.push({
      kind: Kind.INPUT_VALUE_DEFINITION,
      name: { kind: 'Name' as 'Name', value: 'attributeType' },
      type: makeNamedType(ModelResourceIDs.ModelAttributeTypesName()),
      // TODO: Service does not support new style descriptions so wait.
      // description: field.description,
      directives: [],
    });
  }

  if (functions.has('size')) {
    fields.push({
      kind: Kind.INPUT_VALUE_DEFINITION,
      name: { kind: 'Name' as 'Name', value: 'size' },
      type: makeNamedType(ModelResourceIDs.ModelSizeInputTypeName()),
      // TODO: Service does not support new style descriptions so wait.
      // description: field.description,
      directives: [],
    });
  }
github aws-amplify / amplify-cli / packages / graphql-relation-transformer / src / ModelRelationTransformer.ts View on Github external
for (const filter of scalarFilters) {
            if (!this.typeExist(filter.name.value, ctx)) {
                ctx.addInput(filter)
            }
        }

        // Create the ModelXFilterInput
        const tableXQueryFilterInput = makeModelXFilterInputObject(field, ctx)
        if (!this.typeExist(tableXQueryFilterInput.name.value, ctx)) {
            ctx.addInput(tableXQueryFilterInput)
        }

        // Create sort key condition inputs for valid sort key types
        // We only create the KeyConditionInput if it is being used.
        if (sortKeyInfo) {
            const sortKeyConditionInput = makeScalarKeyConditionForType(makeNamedType(sortKeyInfo.typeName))
            if (!this.typeExist(sortKeyConditionInput.name.value, ctx)) {
                ctx.addInput(sortKeyConditionInput);
            }
        }
    }
github aws-amplify / amplify-cli / packages / graphql-dynamodb-transformer / src / DynamoDBModelTransformer.ts View on Github external
}

        // Create the mutations.
        if (shouldMakeCreate) {
            const createInput = makeCreateInputObject(def, nonModelArray, ctx)
            if (!ctx.getType(createInput.name.value)) {
                ctx.addInput(createInput)
            }
            const createResolver = this.resources.makeCreateResolver(def.name.value, createFieldNameOverride)
            const resourceId = ResolverResourceIDs.DynamoDBCreateResolverResourceID(typeName);
            ctx.setResource(resourceId, createResolver)
            ctx.mapResourceToStack(typeName, resourceId);
            mutationFields.push(makeField(
                createResolver.Properties.FieldName,
                [makeInputValueDefinition('input', makeNonNullType(makeNamedType(createInput.name.value)))],
                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)
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-dynamodb-transformer / lib / AppSyncDynamoDBTransformer.js View on Github external
var mutationNameMap = directiveArguments.mutations;
            // Create the mutations.
            if (shouldMakeCreate) {
                var createResolver = _this.resources.makeCreateResolver(def.name.value, createFieldNameOverride);
                ctx.setResource(graphql_transformer_common_2.ResolverResourceIDs.DynamoDBCreateResolverResourceID(typeName), createResolver);
                mutationType = graphql_transformer_common_1.extensionWithFields(mutationType, [graphql_transformer_common_1.makeField(createResolver.Properties.FieldName, [graphql_transformer_common_1.makeArg('input', graphql_transformer_common_1.makeNonNullType(graphql_transformer_common_1.makeNamedType(createInput.name.value)))], graphql_transformer_common_1.makeNamedType(def.name.value))]);
            }
            if (shouldMakeUpdate) {
                var updateResolver = _this.resources.makeUpdateResolver(def.name.value, updateFieldNameOverride);
                ctx.setResource(graphql_transformer_common_2.ResolverResourceIDs.DynamoDBUpdateResolverResourceID(typeName), updateResolver);
                mutationType = graphql_transformer_common_1.extensionWithFields(mutationType, [graphql_transformer_common_1.makeField(updateResolver.Properties.FieldName, [graphql_transformer_common_1.makeArg('input', graphql_transformer_common_1.makeNonNullType(graphql_transformer_common_1.makeNamedType(updateInput.name.value)))], graphql_transformer_common_1.makeNamedType(def.name.value))]);
            }
            if (shouldMakeDelete) {
                var deleteResolver = _this.resources.makeDeleteResolver(def.name.value, deleteFieldNameOverride);
                ctx.setResource(graphql_transformer_common_2.ResolverResourceIDs.DynamoDBDeleteResolverResourceID(typeName), deleteResolver);
                mutationType = graphql_transformer_common_1.extensionWithFields(mutationType, [graphql_transformer_common_1.makeField(deleteResolver.Properties.FieldName, [graphql_transformer_common_1.makeArg('input', graphql_transformer_common_1.makeNonNullType(graphql_transformer_common_1.makeNamedType(deleteInput.name.value)))], graphql_transformer_common_1.makeNamedType(def.name.value))]);
            }
            ctx.addObjectExtension(mutationType);
            if (shouldMakeQuery || shouldMakeList) {
                if (!_this.typeExist('ModelSortDirection', ctx)) {
                    var tableSortDirection = definitions_1.makeModelSortDirectionEnumObject();
                    ctx.addEnum(tableSortDirection);
                }
            }
            // Create query queries
            if (shouldMakeQuery) {
                _this.generateModelXConnectionType(ctx, def);
                var queryResolver = _this.resources.makeQueryResolver(def.name.value, queryFieldNameOverride);
                ctx.setResource(graphql_transformer_common_2.ResolverResourceIDs.DynamoDBQueryResolverResourceID(typeName), queryResolver);
                queryType = graphql_transformer_common_1.extensionWithFields(queryType, [definitions_1.makeModelConnectionField(queryResolver.Properties.FieldName, def.name.value)]);
                _this.generateFilterInputs(ctx, def);
            }
github aws-amplify / amplify-cli / packages / graphql-elasticsearch-transformer / src / definitions.ts View on Github external
.map((field: FieldDefinitionNode) => ({
      kind: Kind.INPUT_VALUE_DEFINITION,
      name: field.name,
      type: makeNamedType(SearchableResourceIDs.SearchableFilterInputTypeName(getBaseType(field.type))),
      // TODO: Service does not support new style descriptions so wait.
      // description: field.description,
      directives: [],
    }));