tailcallhq / tailcall

High Performance GraphQL Runtime
https://tailcall.run
Apache License 2.0
1.29k stars 253 forks source link

Support `@modify` on inputs #2483

Closed tusharmath closed 1 month ago

tusharmath commented 3 months ago

Context Discussion - https://github.com/tailcallhq/tailcall/discussions/2476

The @modify only works on output types. We need to support @modify on input types as well

Proposal

type Query {
  ask(question: Question): Answer
}

type Answer {
  text: [String]
}

input Question {
  prompt: String
  model: String
  system: String @modify(name: "systemPrompt")
}

The generated client schema should look like:

type Query {
  ask(question: Question): Answer
}

type Answer {
  text: [String]
}

input Question {
  prompt: String
  model: String
  systemPrompt: String # Field is renamed
}

Internally Tailcall should handle these field name conversions efficiently.

Technical Requirements

bnchi commented 3 months ago

The current behavior seem to be correct ?!

Current config

schema
  @server(port: 8000)
  @upstream(baseURL: "http://localhost:3000", httpCache: 42, batch: {delay: 100}) {
  query: Query
}

type Query {
  searchUser(input: UserSearch): [User]!
    @http(
      method: POST
      path: "/users/search"
      body: "{{.args.input}}"
    )
}

input UserSearch {
  emailAddress: String! @modify(name: "email_address")
}

type User {
  id: Int!
  name: String!
  email: String!
}

The generated client schema for UserSearch from the playground :

input UserSeach {
 email_address: String!
}
angristan commented 3 months ago

Ok, let me try to make it more clear 🙏 Keep in mind that the issue I'm seeing is that I want to have consistency in the casing of my schema. Having mixed snake case and camel case because of the underlying resolvers is not ideal IMO.

First, @modify doesn't seem to be allowed on inputs:

image

But it does kinda work.

emailAddress: String! @modify(name: "email_address")

Example schema:

schema @server(port: 8000) @upstream(baseURL: "http://localhost:8008") {
  query: Query
}

type Query {
  searchUser(input: UserSearch): [User]!
    @http(method: POST, path: "/users/search", body: "{{.args.input}}")
}

input UserSearch {
  emailAddress: String! @modify(name: "email_address")
}

type User {
  id: Int!
  name: String!
  email: String!
}

Example query:

query test {
  searchUser(input: {email_address: "test@test"}) {
    id
  }
}

Running nc -l 8008 you'll see:

POST /users/search HTTP/1.1
content-type: application/json
accept: */*
user-agent: Tailcall/1.0
host: localhost:8008
content-length: 29

{"email_address":"test@test"}

Issue: the email_address is forced to be snake case in the exposed schema, which breaks consistency. There is no point in using @modify here since the resulting schema is snake case, we could just have:

input UserSearch {
  email_address: String!
}

Which is also snake case :/

email_address: String! @modify(name: "emailAddress")

Schema:

schema @server(port: 8000) @upstream(baseURL: "http://localhost:8008") {
  query: Query
}

type Query {
  searchUser(input: UserSearch): [User]!
    @http(method: POST, path: "/users/search", body: "{{.args.input}}")
}

input UserSearch {
  email_address: String! @modify(name: "emailAddress")
}

type User {
  id: Int!
  name: String!
  email: String!
}

Query:

query test {
  searchUser(input: {emailAddress: "test@test"}) {
    id
  }
}

Payload:

POST /users/search HTTP/1.1
content-type: application/json
accept: */*
user-agent: Tailcall/1.0
host: localhost:8008
content-length: 28

{"emailAddress":"test@test"}

Here is the issue is the opposite, we do have emailAddress in the exposed schema, but it's emailAddress that is serialized, not email_address.

bnchi commented 3 months ago

alright thank you for clarification makes sense now

github-actions[bot] commented 2 months ago

Action required: Issue inactive for 30 days. Status update or closure in 7 days.

karatakis commented 2 months ago

Status update: It is awaiting code review

github-actions[bot] commented 1 month ago

Action required: Issue inactive for 30 days. Status update or closure in 7 days.

github-actions[bot] commented 1 month ago

Issue closed after 7 days of inactivity.