简体   繁体   English

typegraphql:使用变量时在操场上出现参数错误

[英]typegraphql : parameter error in playground when using variables

I'm facing a weird issue, when trying to execute mutations with variables as parameters in the graphql playground 当尝试在graphql游乐场中使用变量作为参数执行突变时,我面临一个奇怪的问题

mutation userLogin($username:String!, $password:String!){
  userLogin(
    username: $username
    password: $password) 
  {
    id
  }
}

Parameters in playground "QUERY VARIABLES" tab: 游乐场“ QUERY VARIABLES”选项卡中的参数:

{
  "username": "test@test.com"
  "password": "Test"
}

this failed with message 这失败并显示消息

{
        "path": "unk",
        "code": "INTERNAL_SERVER_ERROR",
        "message": "Variable \"$username\" of required type \"String!\" was not provided."
      },
      {
        "path": "unk",
        "code": "INTERNAL_SERVER_ERROR",
        "message": "Variable \"$password\" of required type \"String!\" was not provided."
      }

but running this is working well : 但是运行它运行良好:

mutation {
  userLogin(
    username: "test8@test.com"
    password: "Test1234!") 
  {
    id
  }
}

What am I missing here ? 我在这里想念什么?

the variables are @ArgsType 变量是@ArgsType

@ArgsType()
export class LoginInputType {
    @Field()
    username: string;

    @Field()
    password: string;
}

and I declare them in resolver 我在解析器中声明它们

async userLogin(
        @Args() { username, password }: LoginInputType,
        @Ctx() context: GlobalContext
    ): Promise<UsersEntity | null> {

Incorrectly formatting your variables inside Playground will cause it to just not send the variables. 在Playground中错误格式化变量的格式将导致它不发送变量。 If any of the variables were non-null, your request will fail validation. 如果任何变量都不为空,则您的请求将无法通过验证。

This 这个

{
  "username": "test@test.com"
  "password": "Test"
}

is not valid JSON because it's missing a comma. 无效的JSON,因为它缺少逗号。 Playground will shown a red error indicator to the left of any lines that have syntax errors like these. Playground会在任何具有此类语法错误的行的左侧显示一个红色错误指示符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypeGraphQL:使用从本地 Package 导入的 GraphQL class 时出现@Arg 类型错误 - TypeGraphQL : @Arg Type Error when using a GraphQL class imported from a local Package 使用 webpack 和 babel-loader 进行转译时,TypeGraphQL @Arg 装饰器因解析器错误而失败 - TypeGraphQL @Arg decorator fails with parser error when transpiling with webpack and babel-loader 错误:在 typegraphql 中将数组作为输入类型传递时,无法确定 GraphQL 输入类型 - Error: Cannot determine GraphQL input type when passing array as input type in typegraphql 使用 mercurius,使用 typegraphql 进行 fastify 会出错 - Use mercurius, fastify with typegraphql make an error 使用带有 typegraphql 的非标准类型 (BigNumber) - Using a non-standard type (BigNumber) with typegraphql 使用带有箭头函数的泛型类型时出现 Typescript Playground 错误 - Typescript Playground Error on using generic type with Arrow function 打字稿迭代器游乐场错误 - typescript iterators playground error 将此类型用作泛型参数时出现 TypeScript 错误 - TypeScript error when using this type as a generic parameter 在打字稿中使用mixin时提供的参数错误 - Supplied parameter error when using a mixin in typescript 如何使用 TypeGraphQL 和 TypeScript 抑制 TS6133 错误? - How to suppress TS6133 error with TypeGraphQL and TypeScript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM