What should I return in GraphQL mutations with Sequelize?

I am trying to implement a GraphQL server that uses Sequelize in the back-end (for working with MSSQL backstage). And I have a query that works fine (retrieving data from a single SQL table), as expected.

But then I set up the mutation for the same circuit, and when I ran the mutation in GraphiQL, I found that although it does work inside the mutation resolution function (which is to instantiate my Sequelize circuit), it does not return my object to me .

enter image description here

Now I understand this because my Sequelize function .createreturns a promise, and the solution can't handle it?

Here is what I have so far:

resolve(_,args){
  Forecast.create({
    bunit: args.bunit,
    season: args.season,
    position: args.position,
    currency: args.currency,
    settle_date: new Date(args.settle_date),
    reference: args.reference
  }).then(forecast => {
    return forecast;
  }).catch(err => {
    console.error(err);
    return err;
  });
}

, , , , - . , .

+4
2

@Adam . , , .create, , , .

resolve(_,args){
      return Forecast.create({
        bunit: args.bunit,
        season: args.season,
        position: args.position,
        currency: args.currency,
        settle_date: new Date(args.settle_date),
        reference: args.reference
      });
      // .then(forecast => {
      //   console.error(err);
      //   //return forecast;
      // }).catch(err => {
      //   console.error(err);
      //   //return err;
      // });

      //return newForecast;
    }
  }

enter image description here

!

0

then catch , , promises then -chain. then ( catch) return .

, a return Forecast AND then, catch -

resolve(_,args){
      return Forecast.create({
        bunit: args.bunit,
        season: args.season,
        position: args.position,
        currency: args.currency,
        settle_date: new Date(args.settle_date),
        reference: args.reference
      });
       .then(forecast => {
         console.error(err);
         return forecast;
       }).catch(err => {
         console.error(err);
         return err;
       });

      return newForecast;
    }
  }
0

Source: https://habr.com/ru/post/1627446/


All Articles