## Summary: In this commit I remove one of the limitations of our support for interfaces, from #52, by adding support for list-of-interface fields. This was surprisingly complex! The issue is that, as before, it's the containing type that has to do all the glue work -- and it's that glue work that is complicated by list-of-interface fields. All in all, it's not that much new code, and by far the hard part is just 20 lines in the UnmarshalJSON template (which come with almost twice as many lines of comments to explain them). It may be easiest to start by reading some of the generated code, and then read the template. I also added support for such fields with `pointer: true` specified, such that the type is `[][]...[]*MyInterface`, although I don't know why you would want that. This does *not* allow e.g. `*[]*[][]*MyInterface`; that would require a way to specify it (see #16) but also add some extra complexity (as we'd have to actually walk the type-unwrap chain properly, instead of just counting the number of slices and whether there's a pointer). Issue: https://github.com/Khan/genqlient/issues/8 ## Test plan: make check Author: benjaminjkraft Reviewers: dnerdy, benjaminjkraft, aberkan, csilvers, MiguelCastillo Required Reviewers: Approved by: dnerdy Checks: ⌛ Test (1.17), ⌛ Test (1.16), ⌛ Test (1.15), ⌛ Test (1.14), ⌛ Test (1.13), ⌛ Lint, ⌛ Lint, ⌛ Test (1.17), ⌛ Test (1.16), ⌛ Test (1.15), ⌛ Test (1.14), ⌛ Test (1.13) Pull request URL: https://github.com/Khan/genqlient/pull/54
120 lines
3.0 KiB
GraphQL
120 lines
3.0 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
|
|
}
|
|
|
|
"""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]
|
|
}
|
|
|
|
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!]!
|
|
}
|
|
|
|
"""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
|
|
}
|
|
|
|
"""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!
|
|
text: String!
|
|
}
|
|
|
|
type Video implements Content {
|
|
"""ID is documented in the Content interface."""
|
|
id: ID!
|
|
name: String!
|
|
parent: Topic!
|
|
duration: Int!
|
|
}
|
|
|
|
type Topic implements Content {
|
|
"""ID is documented in the Content interface."""
|
|
id: ID!
|
|
name: String!
|
|
parent: Topic
|
|
children: [Content!]!
|
|
}
|
|
|
|
"""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!]!]!]!
|
|
}
|
|
|
|
type Mutation {
|
|
createUser(name: String!, email: String): User
|
|
}
|