How to use the graphql-transformer-common.ResolverResourceIDs.ResolverResourceID 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-auth-transformer / src / ModelAuthTransformer.ts View on Github external
private addSubscriptionResolvers(ctx: TransformerContext, rules: AuthRule[],
        parent: ObjectTypeDefinitionNode, level: string, fieldName: string) {
        const resolverResourceId = ResolverResourceIDs.ResolverResourceID("Subscription", fieldName);
        const resolver = this.resources.generateSubscriptionResolver(fieldName);
        // If the data source does not exist it is created and added as a resource for PUBLIC && ON levels
        const noneDS = ctx.getResource(ResourceConstants.RESOURCES.NoneDataSource)

        // add the rules in the subscription resolver
        if (!rules || rules.length === 0) {
            return;
        } else if (level === "PUBLIC") {
            // set the resource with no auth logic
            ctx.setResource(resolverResourceId, resolver);
        } else {
            // Break the rules out by strategy.
            const staticGroupAuthorizationRules = this.getStaticGroupRules(rules);
            const ownerAuthorizationRules = this.getOwnerRules(rules);

            const staticGroupAuthorizationExpression = this.resources.staticGroupAuthorizationExpression(
github aws-amplify / amplify-cli / packages / graphql-http-transformer / src / HttpTransformer.ts View on Github external
field.name.value,
            queryBodyArgsArray.filter(a => a.type.kind === Kind.NON_NULL_TYPE).map(a => a.name.value),
            headers
          );
          ctx.setResource(putResourceID, putResolver);
        }
        break;
      case 'DELETE':
        const deleteResourceID = ResolverResourceIDs.ResolverResourceID(parent.name.value, field.name.value);
        if (!ctx.getResource(deleteResourceID)) {
          const deleteResolver = this.resources.makeDeleteResolver(baseURL, path, parent.name.value, field.name.value, headers);
          ctx.setResource(deleteResourceID, deleteResolver);
        }
        break;
      case 'PATCH':
        const patchResourceID = ResolverResourceIDs.ResolverResourceID(parent.name.value, field.name.value);
        if (!ctx.getResource(patchResourceID)) {
          const patchResolver = this.resources.makePatchResolver(
            baseURL,
            path,
            parent.name.value,
            field.name.value,
            queryBodyArgsArray.filter(a => a.type.kind === Kind.NON_NULL_TYPE).map(a => a.name.value),
            headers
          );
          ctx.setResource(patchResourceID, patchResolver);
        }
        break;
      default:
      // nothing
    }
github aws-amplify / amplify-cli / packages / graphql-function-transformer / src / FunctionTransformer.ts View on Github external
if (!ctx.getResource(lambdaDataSourceKey)) {
      ctx.setResource(lambdaDataSourceKey, this.datasource(name, region));
      ctx.mapResourceToStack(FUNCTION_DIRECTIVE_STACK, lambdaDataSourceKey);
    }

    // Add function that invokes the lambda function
    const functionConfigurationKey = FunctionResourceIDs.FunctionAppSyncFunctionConfigurationID(name, region);
    if (!ctx.getResource(functionConfigurationKey)) {
      ctx.setResource(functionConfigurationKey, this.function(name, region));
      ctx.mapResourceToStack(FUNCTION_DIRECTIVE_STACK, functionConfigurationKey);
    }

    // Add resolver that invokes our function
    const typeName = parent.name.value;
    const fieldName = definition.name.value;
    const resolverKey = ResolverResourceIDs.ResolverResourceID(typeName, fieldName);
    const resolver = ctx.getResource(resolverKey);
    if (!resolver) {
      ctx.setResource(resolverKey, this.resolver(typeName, fieldName, name, region));
      ctx.mapResourceToStack(FUNCTION_DIRECTIVE_STACK, resolverKey);
    } else if (resolver.Properties.Kind === 'PIPELINE') {
      ctx.setResource(
        resolverKey,
        this.appendFunctionToResolver(resolver, FunctionResourceIDs.FunctionAppSyncFunctionConfigurationID(name, region))
      );
    }
  };
github aws-amplify / amplify-cli / packages / graphql-auth-transformer / src / ModelAuthTransformer.ts View on Github external
private protectQueries(ctx: TransformerContext, def: ObjectTypeDefinitionNode, rules: AuthRule[]) {
        const secondaryKeyDirectivesWithQueries = (def.directives || []).filter(d => {
            const isKey = d.name.value === 'key';
            const args = getDirectiveArguments(d);
            // @key with a name is a secondary key.
            const isSecondaryKey = Boolean(args.name);
            const hasQueryField = Boolean(args.queryField);
            return isKey && isSecondaryKey && hasQueryField;
        });
        for (const keyWithQuery of secondaryKeyDirectivesWithQueries) {
            const args = getDirectiveArguments(keyWithQuery);
            const resolverResourceId = ResolverResourceIDs.ResolverResourceID(ctx.getQueryTypeName(), args.queryField);
            this.protectListQuery(ctx, resolverResourceId, rules)
        }
    }
github aws-amplify / amplify-cli / packages / graphql-connection-transformer / src / ModelConnectionTransformer.ts View on Github external
validateKeyField(existingKeyField);

            const tableLogicalId = ModelResourceIDs.ModelTableResourceID(parentTypeName)
            const table = ctx.getResource(tableLogicalId) as Table
            const sortField = associatedSortField ? { name: associatedSortFieldName, type: sortType } : null
            const updated = this.resources.updateTableForConnection(table, connectionName, connectionAttributeName,
                sortField)
            ctx.setResource(tableLogicalId, updated)

            const getResolver = this.resources.makeGetItemConnectionResolver(
                parentTypeName,
                fieldName,
                relatedTypeName,
                connectionAttributeName
            )
            ctx.setResource(ResolverResourceIDs.ResolverResourceID(parentTypeName, fieldName), getResolver)

            // Update the create & update input objects for this
            const createInputName = ModelResourceIDs.ModelCreateInputObjectName(parentTypeName)
            const createInput = ctx.getType(createInputName) as InputObjectTypeDefinitionNode
            if (createInput) {
                const updated = updateCreateInputWithConnectionField(createInput, connectionAttributeName, leftConnectionIsNonNull)
                ctx.putType(updated)
            }
            const updateInputName = ModelResourceIDs.ModelUpdateInputObjectName(parentTypeName)
            const updateInput = ctx.getType(updateInputName) as InputObjectTypeDefinitionNode
            if (updateInput) {
                const updated = updateUpdateInputWithConnectionField(updateInput, connectionAttributeName)
                ctx.putType(updated)
            }

        } else if (leftConnectionIsList) {
github aws-amplify / amplify-cli / packages / graphql-http-transformer / src / HttpTransformer.ts View on Github external
ctx.addInput(bodyInputObject);
        newFieldArgsArray.push(makeHttpArgument('body', bodyInputObject, makeNonNull));
      }
    }

    // build the payload
    switch (method) {
      case 'GET':
        const getResourceID = ResolverResourceIDs.ResolverResourceID(parent.name.value, field.name.value);
        if (!ctx.getResource(getResourceID)) {
          const getResolver = this.resources.makeGetResolver(baseURL, path, parent.name.value, field.name.value, headers);
          ctx.setResource(getResourceID, getResolver);
        }
        break;
      case 'POST':
        const postResourceID = ResolverResourceIDs.ResolverResourceID(parent.name.value, field.name.value);
        if (!ctx.getResource(postResourceID)) {
          const postResolver = this.resources.makePostResolver(
            baseURL,
            path,
            parent.name.value,
            field.name.value,
            queryBodyArgsArray.filter(a => a.type.kind === Kind.NON_NULL_TYPE).map(a => a.name.value),
            headers
          );
          ctx.setResource(postResourceID, postResolver);
        }
        break;
      case 'PUT':
        const putResourceID = ResolverResourceIDs.ResolverResourceID(parent.name.value, field.name.value);
        if (!ctx.getResource(putResourceID)) {
          const putResolver = this.resources.makePutResolver(
github aws-amplify / amplify-cli / packages / graphql-http-transformer / src / HttpTransformer.ts View on Github external
case 'POST':
        const postResourceID = ResolverResourceIDs.ResolverResourceID(parent.name.value, field.name.value);
        if (!ctx.getResource(postResourceID)) {
          const postResolver = this.resources.makePostResolver(
            baseURL,
            path,
            parent.name.value,
            field.name.value,
            queryBodyArgsArray.filter(a => a.type.kind === Kind.NON_NULL_TYPE).map(a => a.name.value),
            headers
          );
          ctx.setResource(postResourceID, postResolver);
        }
        break;
      case 'PUT':
        const putResourceID = ResolverResourceIDs.ResolverResourceID(parent.name.value, field.name.value);
        if (!ctx.getResource(putResourceID)) {
          const putResolver = this.resources.makePutResolver(
            baseURL,
            path,
            parent.name.value,
            field.name.value,
            queryBodyArgsArray.filter(a => a.type.kind === Kind.NON_NULL_TYPE).map(a => a.name.value),
            headers
          );
          ctx.setResource(putResourceID, putResolver);
        }
        break;
      case 'DELETE':
        const deleteResourceID = ResolverResourceIDs.ResolverResourceID(parent.name.value, field.name.value);
        if (!ctx.getResource(deleteResourceID)) {
          const deleteResolver = this.resources.makeDeleteResolver(baseURL, path, parent.name.value, field.name.value, headers);