atulmy/gql-query-builder

support for primitive return types?

albertalquisola opened this issue · 3 comments

it seems the builder expects an object to always be returned in a graphql response since the fields arg is required. But what if the graphql server responds with a primitive? (eg. GraphQLBoolean)

Example:

// mutation portion of schema
new GraphQLObjectType({
  name: 'RootMutation',
  fields: { 
    logout: {
      type: GraphQLBoolean,
      resolve: async () => await pretendToLogUserOut(), // returns boolean
    }
  }
});
// query
import { mutation } from 'gql-query-builder';

const logoutMutation = mutation({ operation: 'logout', fields: [] });
console.log(logoutMutation.query);
// query output
mutation {
  logout {
    // this causes a 400 since i dont list any fields but that's because the response doesnt return `fields`, it just returns a bool
  }
}

// desired query output
mutation {
  logout
}

The result is a 400 since this is a malformed query string so it seems the query builder does not have support for handling primitive return values?

I'm unsure how this addresses the issue? I dont need to specify a custom variable type (i dont think), I need my query output to not always expect an object being returned

Sorry got it, you want the fields to be optional

Screenshot 2019-05-29 at 12 15 04 AM