Files
genqlient/generate/testdata/queries/schema.graphql
T
Ben KraftandGitHub fcae8dd1d7 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
2021-09-15 18:06:43 -07:00

171 lines
3.9 KiB
GraphQL

"""DateTime is a scalar.
We don't really have anything useful to do with this description though.
"""
scalar DateTime
scalar Junk
scalar ComplexJunk
"""Role is a type a user may have."""
enum Role {
"""What is a student?
A student is primarily a person enrolled in a school or other educational institution and who is under learning with goals of acquiring knowledge, developing professions and achieving employment at desired field. In the broader sense, a student is anyone who applies themselves to the intensive intellectual engagement with some matter necessary to master it as part of some practical affair in which such mastery is basic or decisive.
(from [Wikipedia](https://en.wikipedia.org/wiki/Student))
"""
STUDENT
"""Teacher is a teacher, who teaches the students."""
TEACHER
}
input PokemonInput {
species: String!
level: Int!
}
type Pokemon {
species: String!
level: Int!
}
"""UserQueryInput is the argument to Query.users.
Ideally this would support anything and everything!
Or maybe ideally it wouldn't.
Really I'm just talking to make this documentation longer.
"""
input UserQueryInput {
email: String
name: String
"""id looks the user up by ID. It's a great way to look up users."""
id: ID
role: Role
names: [String]
hasPokemon: PokemonInput
}
type AuthMethod {
provider: String
email: String
}
"""A User is a user!"""
type User {
"""id is the user's ID.
It is stable, unique, and opaque, like all good IDs."""
id: ID!
roles: [Role!]
name: String
emails: [String!]!
emailsOrNull: [String!]
emailsWithNulls: [String]!
emailsWithNullsOrNull: [String]
authMethods: [AuthMethod!]!
pokemon: [Pokemon!]
greeting: Clip
}
"""An audio clip, such as of a user saying hello."""
type Clip implements HasDuration {
id: ID!
duration: Int!
}
"""Content is implemented by various types like Article, Video, and Topic."""
interface Content {
"""ID is the identifier of the content."""
id: ID!
name: String!
parent: Topic
url: String!
}
"""An object with a duration, like a video."""
interface HasDuration {
duration: Int!
}
"""LeafContent represents content items that can't have child-nodes."""
union LeafContent = Article | Video
type Article implements Content {
"""ID is documented in the Content interface."""
id: ID!
name: String!
parent: Topic!
url: String!
text: String!
thumbnail: StuffThumbnail
}
type StuffThumbnail { # for articles, but let's give the name-generator a hard time.
id: ID!
thumbnailUrl: String!
}
type Video implements Content & HasDuration {
"""ID is documented in the Content interface."""
id: ID!
name: String!
parent: Topic!
url: String!
duration: Int!
thumbnail: Thumbnail
}
type Thumbnail { # for videos, but let's give the name-generator a hard time.
id: ID!
timestampSec: Int!
}
type Topic implements Content {
"""ID is documented in the Content interface."""
id: ID!
name: String!
parent: Topic
url: String!
children: [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.
See UserQueryInput for what stuff is supported.
If query is null, returns the current user.
"""
user(query: UserQueryInput): User
users(query: [UserQueryInput]): [User]
"""usersWithRole looks a user up by role."""
usersWithRole(role: Role!): [User!]!
root: Topic!
randomItem: Content!
randomLeaf: LeafContent!
convert(dt: DateTime!, tz: String): DateTime!
maybeConvert(dt: DateTime, tz: String): DateTime
getJunk: Junk
getComplexJunk: ComplexJunk
listOfListsOfLists: [[[String!]!]!]!
listOfListsOfListsOfContent: [[[Content!]!]!]!
recur(input: RecursiveInput!): Recursive
}
type Mutation {
createUser(name: String!, email: String): User
}