【问题标题】:Flutter_graphql mutation not triggering apollo server resolverFlutter_graphql 突变未触发阿波罗服务器解析器
【发布时间】:2019-10-08 00:37:54
【问题描述】:

我正在创建一个 Flutter 应用程序并重用一个 appolographql 服务器。 问题是当我在 Flutter 中变异时,解析器功能没有被触发。

解析器在使用 Playground 时被触发,但不是 Flutter。

这是 Flutter 代码:

Mutation(
  options: MutationOptions(
    document: r"""
      mutation createOrUpdateHorse($horse:HorseInput,$entityid:ID) {
        createOrUpdateHorse(horse:$horse,entityid:$entityid) {
          id
          name
          status
          rating
        }
      }
    """,
    // variables: {
    //   "horse": {"id": 1, "status": "bu"},
    //   "entityid": 1
    // },
  ),
  builder: (
    RunMutation runMutation,
    QueryResult result,
  ) {
    return IconButton(
      icon: Icon(Icons.cloud_upload),
      onPressed: () => runMutation({
            "horse": {"id": 1, "status": "bu"},
            "entityid": 1
          }),
    );
  },
  onCompleted: (resultData) {
    print(resultData);
  },
),

这是在颤振突变的情况下服务器收到的请求正文

{ operationName: 'createOrUpdateHorse',
  variables: { entityid: 1, horse: { id: 1, status: 'bu' } },
  query:
   'mutation createOrUpdateHorse($horse:HorseInput,$entityid:ID) {\n                  createOrUpdateHorse(horse:$horse,entityid:$entityid) {\n                    
   id\n
   status\n
   }\n
  }\n
' }

这是在 Playground 突变的情况下服务器收到的请求正文

{operationName:null,
variables:{},
query:
 mutation {\n  
   createOrUpdateHorse(horse: {id: 1, status: \"alo\"}, entityid: 5) 
{\n    
  id\n
  status\n  
}\n
}\n
}

【问题讨论】:

    标签: flutter graphql apollo-server


    【解决方案1】:

    我的错,这是一个愚蠢的错误,我忘记了“!”用于 HorseInput!。

    【讨论】:

      【解决方案2】:

      您使用的是哪个版本的 graphql_flutter? 在 ^1.0.1 版本中 - 突变看起来是这样的:

      r'''
      mutation createOrUpdateHorse(
              $horse: HorseInput,
              $entityid: ID
              ){
              action: createOrUpdateHorse(
                input: {
                  horse: $horse,
                  entityid: $entityid
                }){
                  id
                  name
                  status
                  rating
                }
            } 
      '''
      

      【讨论】:

        猜你喜欢
        • 2019-09-15
        • 2019-02-08
        • 2021-09-09
        • 2020-02-15
        • 2019-04-02
        • 2017-03-23
        • 2019-03-06
        • 2020-01-14
        • 2020-06-27
        相关资源
        最近更新 更多