aws cdk appsync架构创建状态为FAILED,详细信息:保存架构时发生内部故障

问题描述 投票:0回答:1

给出以下graphql模式

# graphql/schema.graphql
type AppUser {
  userId: String
  fullName: String
}

type Query {
  getUser(userId: String): AppUser
  getUsers(): [AppUser]
}

type Mutation {
  addUser(user: AppUser!): AppUser
}

以及以下在lib / mystack.ts中定义的cdk代码:


    const graphql = new appsync.GraphQLApi(this, 'GraphQLApi', {
      name: 'metrolens-graphql-api',
      logConfig: {
        fieldLogLevel: appsync.FieldLogLevel.ALL,
      },
      authorizationConfig: {
        defaultAuthorization: {
          // userPool,
          defaultAction: appsync.UserPoolDefaultAction.ALLOW,
        },
        // additionalAuthorizationModes: [{ apiKeyDesc: 'My API Key' }],
      },
      schemaDefinitionFile: props?.schemaDirectory,
    })

    const lambdaRegister = new nodejs.NodejsFunction(this, 'register', {
      functionName: 'register',
      runtime: lambda.Runtime.NODEJS_12_X,
      timeout: cdk.Duration.seconds(10),
      entry: './lambda/register/register-0.ts',
      handler: 'handler',
      layers: [layer],
      description: 'Register a user.',
    })

    const lambdaLogin = new nodejs.NodejsFunction(this, 'login', {
      functionName: 'login',
      runtime: lambda.Runtime.NODEJS_12_X,
      timeout: cdk.Duration.seconds(10),
      entry: './lambda/login/login-0.ts',
      handler: 'handler',
      layers: [layer],
      description: 'Login a user.',
    })

    const lambdaRegisterDataSource = graphql.addLambdaDataSource(
      'lambdaRegister',
      'Register lambda triggered by appsync',
      lambdaRegister
    )
    lambdaRegisterDataSource.createResolver({
      typeName: 'Mutation',
      fieldName: 'addUser',
      requestMappingTemplate: appsync.MappingTemplate.lambdaRequest(),
      responseMappingTemplate: appsync.MappingTemplate.lambdaResult(),
    })

    const lambdaLoginDataSource = graphql.addLambdaDataSource(
      'lambdaLogin',
      'Login lambda triggered by appsync',
      lambdaLogin
    )

    lambdaLoginDataSource.createResolver({
      typeName: 'Query',
      fieldName: 'getUsers',
      requestMappingTemplate: appsync.MappingTemplate.lambdaRequest(),
      responseMappingTemplate: appsync.MappingTemplate.lambdaResult(),
    })

我在AWS::AppSync::GraphQLSchema部署阶段收到以下错误消息:

[GraphQLApi / Schema(GraphQLApiSchema5937B126)架构创​​建状态为FAILED,详细信息:保存架构时发生内部故障。

以前有人遇到此错误吗?我怀疑我的graphql模式有问题,但是我无法确定它是什么。另一个答案提到,即使您不使用DynamoDB,位于https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ReservedWords.html的DynamoDB保留字也可能导致冲突,因此我将User类型重命名为AppSync。但是,看起来Query也是保留字,但据我了解,这对于graphql定义也是必需的。请帮忙。 AWS CDK很难吸。

typescript aws-lambda graphql aws-appsync aws-cdk
1个回答
0
投票

getUsers(): [AppUser]更新为getUsers: [AppUser]

我遇到了同样的错误,并将我的架构插入验证器中,发现了错误。

输入您的礼物给>]

{
  "error": "Syntax error while parsing GraphQL query. Invalid input \"{\\n  getUser(userId: String): AppUser\\n  getUsers()\", expected ImplementsInterfaces, Directives, FieldDefinition or Comments (line 6, column 12):\ntype Query {\n           ^"
}
© www.soinside.com 2019 - 2024. All rights reserved.