Skip to content

Handle resolving a null field with @http #2467

@amitksingh1490

Description

@amitksingh1490

Discussed in #2466

Originally posted by angristan July 19, 2024
With this example:

schema @server(port: 8000) @upstream(baseURL: "http://jsonplaceholder.typicode.com") {
  query: Query
}

type Query {
  users: [User] @http(path: "/users")
}

type User {
  id: Int!
  name: String!
  username: String!
  email: String!
  authorID: String

  posts: [Post]
    @http(
      path: "/posts"
      query: [{ key: "author_ids[]", value: "{{.value.authorID}}" }]
      batchKey: ["author_ids[]"]
    )
}

type Post {
  id: Int!
  title: String!
  body: String!
}

If authorID is not nil, it works as expected, however if it is nil, it calls /posts without any query param, thus returning unrelated posts.

Expected url
https://jsonplaceholder.typicode.com/posts?userId=
Actual url
https://jsonplaceholder.typicode.com/posts

By default this should be the behaviour

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions