Add support for specifying type-names, and conflict-detection (#94)
## Summary: In this commit I add two related features to genqlient: conflict-detection to avoid generating two distinct types with the same name, and an option to specify the type-name genqlient should use for some type. The conflict-detection was pretty simple once I realized I had already written all the code to do it in #70. There was a bunch of wiring, since we now need to keep track of the GraphQL type/selection-set that each type corresponds to, but it was pretty straightforward. This allows us to: - detect and reject if you have really sneaky type-names (there are some examples documented in `names.go`) - more clearly crash if genqlient accidentally generates two conflicting types, and - avoid stack-overflow when handing recursive (input) types (although sadly the poor support for options on input types (#14) makes them difficult to use in many cases; you really need to be able to set `pointer: true`) And with that all set up, the type-naming was also easy! (It doesn't have to get into the core of the type-generator, just plug in where we choose names. The desire for conflict detection was the main reason I hadn't set it up already.) Note that the existing limitation of #70 that the fields have to be in exactly the same order remains (and is now documented as #93); it's not deeply hard to fix but it's surprisingly much work. Issue: https://github.com/Khan/genqlient/issues/60 Issue: https://github.com/Khan/genqlient/issues/12 ## Test plan: make check Author: benjaminjkraft Reviewers: StevenACoffman, jvoll, benjaminjkraft, aberkan, csilvers, dnerdy, mahtabsabet, MiguelCastillo Required Reviewers: Approved By: StevenACoffman, jvoll Checks: ✅ Test (1.17), ✅ Test (1.16), ✅ Test (1.15), ✅ Test (1.14), ✅ Lint, ✅ Test (1.17), ✅ Test (1.16), ✅ Test (1.15), ✅ Test (1.14), ✅ Lint Pull Request URL: https://github.com/Khan/genqlient/pull/94
This commit is contained in:
+6
@@ -0,0 +1,6 @@
|
||||
query Recursion($input: RecursiveInput!) {
|
||||
recur(input: $input) {
|
||||
# (sadly, or happily, GraphQL doesn't let us recur infinitely here)
|
||||
rec { rec { rec { id } } }
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
# @genqlient(typename: "Resp")
|
||||
query TypeNames {
|
||||
# @genqlient(typename: "User")
|
||||
user { id name }
|
||||
# @genqlient(typename: "Item")
|
||||
randomItem { id name }
|
||||
# (ok to reuse the name as long as they match)
|
||||
# @genqlient(typename: "User")
|
||||
users { id name }
|
||||
}
|
||||
+11
-1
@@ -131,6 +131,15 @@ type Topic implements Content {
|
||||
schoolGrade: String
|
||||
}
|
||||
|
||||
input RecursiveInput {
|
||||
rec: [RecursiveInput]
|
||||
}
|
||||
|
||||
type Recursive {
|
||||
id: ID!
|
||||
rec: Recursive
|
||||
}
|
||||
|
||||
"""Query's description is probably ignored by almost all callers."""
|
||||
type Query {
|
||||
"""user looks up a user by some stuff.
|
||||
@@ -140,7 +149,7 @@ type Query {
|
||||
"""
|
||||
user(query: UserQueryInput): User
|
||||
|
||||
users(query: [UserQueryInput]): User
|
||||
users(query: [UserQueryInput]): [User]
|
||||
|
||||
"""usersWithRole looks a user up by role."""
|
||||
usersWithRole(role: Role!): [User!]!
|
||||
@@ -153,6 +162,7 @@ type Query {
|
||||
getComplexJunk: ComplexJunk
|
||||
listOfListsOfLists: [[[String!]!]!]!
|
||||
listOfListsOfListsOfContent: [[[Content!]!]!]!
|
||||
recur(input: RecursiveInput!): Recursive
|
||||
}
|
||||
|
||||
type Mutation {
|
||||
|
||||
Reference in New Issue
Block a user