[GH-ISSUE #12] support for primitive return types? #4

Closed
opened 2026-03-03 00:02:40 +03:00 by kerem · 3 comments
Owner

Originally created by @albertalquisola on GitHub (May 27, 2019).
Original GitHub issue: https://github.com/atulmy/gql-query-builder/issues/12

Originally assigned to: @atulmy on GitHub.

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?

Originally created by @albertalquisola on GitHub (May 27, 2019). Original GitHub issue: https://github.com/atulmy/gql-query-builder/issues/12 Originally assigned to: @atulmy on GitHub. 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?
kerem 2026-03-03 00:02:40 +03:00
Author
Owner

@atulmy commented on GitHub (May 28, 2019):

Check: https://github.com/atulmy/gql-query-builder/issues/8#issuecomment-481789433

<!-- gh-comment-id:496539826 --> @atulmy commented on GitHub (May 28, 2019): Check: https://github.com/atulmy/gql-query-builder/issues/8#issuecomment-481789433
Author
Owner

@albertalquisola commented on GitHub (May 28, 2019):

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

<!-- gh-comment-id:496621345 --> @albertalquisola commented on GitHub (May 28, 2019): 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
Author
Owner

@atulmy commented on GitHub (May 28, 2019):

Sorry got it, you want the fields to be optional

Screenshot 2019-05-29 at 12 15 04 AM

<!-- gh-comment-id:496641081 --> @atulmy commented on GitHub (May 28, 2019): Sorry got it, you want the `fields` to be optional ![Screenshot 2019-05-29 at 12 15 04 AM](https://user-images.githubusercontent.com/685786/58503762-de8f5380-81a6-11e9-84ef-da312df40189.png)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/gql-query-builder#4
No description provided.