0

My resolver get

{ adminMsg: 
   [ 
     {active: “y”, text1: “blah1" } , 
     {active: “n”, text1: “blah2" } 
   ] };

My query:

{
  adminWarn {
    adminMsg {
      active, text1
    }
  }
}

I want only array-elements with condition: active = 'y'

I find in GQL Dokumentation no way to write this condition im my query. Is there any solution in GQL?

1 Answer 1

1

Use of resolve args can solve the problem:

const adminWarnList = new GraphQLObjectType({
    name: 'adminWarnReportList',
    fields: () => ({
        adminMsg: {
            type: new GraphQLList(adminWarnFields),
        },
    }),
});

const adminWarn = {
    type: adminWarnList,
    args: {
        active: { type: GraphQLString },
    },
    resolve: (parent, args, context) => {
       ...
       let reportdata = context.loadData();

       if (args.active == 'y') {
                    let filteredItems = reportdata.filter(function(item) {
                        return item.active != null && item.active != 'y';
                    });

                    reportdata = filteredItems;
        }

        return { adminMsg: reportdata };
    },
};
Sign up to request clarification or add additional context in comments.

1 Comment

This isn't graphql?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.