简体   繁体   中英

Flutter_graphql mutation not triggering apollo server resolver

I'm creating a Flutter application and reusing a appolographql server. The issue is that when i'm Mutating in Flutter, the resolver function is not being triggered.

The resolver is being triggered when using the playground, but not with flutter.

This is the Flutter code :

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);
  },
),

This is the request body the server receives in the case of a flutter mutation

{ 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
' }

This is the request body the server receives in the case of a playground mutation

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

Which version of graphql_flutter are you using? in version ^1.0.1 - mutation looks so:

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

My bad it was a stupid mistake, I forgot the "!" for HorseInput!.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM