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

Root query: generate {x}Option method for fields with an optional interface type #1223

Merged
merged 3 commits into from
Dec 22, 2021

Conversation

iRevive
Copy link
Contributor

@iRevive iRevive commented Dec 22, 2021

ClientWriter does not handle optional interfaces properly of the root query.

I fixed the processing of the root query in the scope of the PR. If the output type of a field is an interface, the ClientWriter will generate two methods: def {x}(...) and def {x}Option(...).

Schema 1 (without root schema)

type Queries {
  node(id: ID!): Node
}
interface Node {
  id: ID!
}
type NodeA implements Node {
  id: ID!
  a: String
}
type NodeB implements Node {
  id: ID!
  b: Int
}

ClientWriter generates two methods: node(id: ID)(...) and nodeOption(id: ID)(...).

Schema 2 (with top-level schema definition)

+ schema {
+  query: Queries
+}
type Queries {
  node(id: ID!): Node
}
interface Node {
  id: ID!
}
type NodeA implements Node {
  id: ID!
  a: String
}
type NodeB implements Node {
  id: ID!
  b: Int
}

ClientWriter generates only one method: node(id: ID)(...).

Copy link
Owner

@ghostdogpr ghostdogpr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Shouldn't the same thing be applied to mutations and subscriptions?

@iRevive
Copy link
Contributor Author

iRevive commented Dec 22, 2021

Good point. I guess mutations and subscriptions should be updated as well. I will push an update soon.

@iRevive
Copy link
Contributor Author

iRevive commented Dec 22, 2021

Done

Copy link
Owner

@ghostdogpr ghostdogpr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@ghostdogpr ghostdogpr merged commit cf1b051 into ghostdogpr:master Dec 22, 2021
@iRevive iRevive deleted the root-query-optional-interface branch December 22, 2021 17:23
Fluxx pushed a commit to Fluxx/caliban that referenced this pull request Jan 24, 2022
…nterface type (ghostdogpr#1223)

* Root query: generate `{x}Option` method for fields with an optional interface type

* Root mutation/subscription: generate `{x}Option` method for fields with an optional interface type

* Fix root mutation
Fluxx pushed a commit to Fluxx/caliban that referenced this pull request Jan 27, 2022
…nterface type (ghostdogpr#1223)

* Root query: generate `{x}Option` method for fields with an optional interface type

* Root mutation/subscription: generate `{x}Option` method for fields with an optional interface type

* Fix root mutation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants