Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

null in params is converted to an empty object #187

Closed
zabavnikov opened this issue Nov 30, 2020 · 4 comments · Fixed by #194
Closed

null in params is converted to an empty object #187

zabavnikov opened this issue Nov 30, 2020 · 4 comments · Fixed by #194
Assignees
Labels
bug Something isn't working

Comments

@zabavnikov
Copy link

zabavnikov commented Nov 30, 2020

Code:
image

Error: (I expect null)
image

@zabavnikov
Copy link
Author

Now I use this solution
image

@acro5piano
Copy link
Owner

acro5piano commented Dec 5, 2020

@zabavnikov

Sorry for the delay. Thank you for your report.

Solution 1: use GraphQL operation variables

The better solution.

const travelsQuery = gql('query($page: Int!, $top: Int!)', {
  travels: params({ page: '$page', top: '$top' }, {
    data: {
      id: types.number,
    }
  })
})
axios.post({
  query: travelsQuery.toString(),
  variables: { page: page || 1, top: top || null,  }
})

Solution 2: alias

How about using alias?

const travelsQuery = gql({
  [alias('travels', `travels(page: ${query.page || 1}, top: ${query.top || 'null'})`]: {
    data: {
      id: types.number,
    }
  }
})

@acro5piano
Copy link
Owner

I'll try to render null if the param is null.

@acro5piano
Copy link
Owner

@zabavnikov I've fixed and published v3.0.1 which includes the fix. Please try it out! Thanks.

@acro5piano acro5piano self-assigned this Dec 5, 2020
@acro5piano acro5piano added the bug Something isn't working label Dec 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants