interfaces themselves are actually trivial!
This commit is contained in:
@@ -60,8 +60,9 @@ TODO(benkraft): Figure out how to get GitHub Actions to run the example -- it ne
|
|||||||
## Major TODOs
|
## Major TODOs
|
||||||
|
|
||||||
Query structures to support:
|
Query structures to support:
|
||||||
- interfaces
|
- unions
|
||||||
- fragments
|
- fragments
|
||||||
|
- `__typename`
|
||||||
|
|
||||||
Config options:
|
Config options:
|
||||||
- get schema via HTTP (perhaps even via GraphQL introspection)
|
- get schema via HTTP (perhaps even via GraphQL introspection)
|
||||||
|
|||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
root {
|
||||||
|
id
|
||||||
|
name
|
||||||
|
children {
|
||||||
|
id
|
||||||
|
name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
type Response struct {
|
||||||
|
Root struct {
|
||||||
|
Id string `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Children []content `json:"children"`
|
||||||
|
} `json:"root"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type content struct {
|
||||||
|
Id string `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
||||||
Vendored
+28
@@ -26,6 +26,34 @@ type User {
|
|||||||
authMethods: [AuthMethod!]!
|
authMethods: [AuthMethod!]!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface Content {
|
||||||
|
id: ID!
|
||||||
|
name: String!
|
||||||
|
parent: Topic
|
||||||
|
}
|
||||||
|
|
||||||
|
type Article implements Content {
|
||||||
|
id: ID!
|
||||||
|
name: String!
|
||||||
|
parent: Topic!
|
||||||
|
text: String!
|
||||||
|
}
|
||||||
|
|
||||||
|
type Video implements Content {
|
||||||
|
id: ID!
|
||||||
|
name: String!
|
||||||
|
parent: Topic!
|
||||||
|
duration: Int!
|
||||||
|
}
|
||||||
|
|
||||||
|
type Topic implements Content {
|
||||||
|
id: ID!
|
||||||
|
name: String!
|
||||||
|
parent: Topic
|
||||||
|
children: [Content!]!
|
||||||
|
}
|
||||||
|
|
||||||
type Query {
|
type Query {
|
||||||
user(query: UserQueryInput): User
|
user(query: UserQueryInput): User
|
||||||
|
root: Topic!
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -222,7 +222,7 @@ func (builder *typeBuilder) writeType(typ *ast.Type, selectionSet []selection, i
|
|||||||
|
|
||||||
func (builder *typeBuilder) writeTypedef(typedef *ast.Definition, selectionSet []selection) error {
|
func (builder *typeBuilder) writeTypedef(typedef *ast.Definition, selectionSet []selection) error {
|
||||||
switch typedef.Kind {
|
switch typedef.Kind {
|
||||||
case ast.Object, ast.InputObject:
|
case ast.Object, ast.InputObject, ast.Interface:
|
||||||
builder.WriteString("struct {\n")
|
builder.WriteString("struct {\n")
|
||||||
for _, field := range selectionSet {
|
for _, field := range selectionSet {
|
||||||
err := builder.writeField(field)
|
err := builder.writeField(field)
|
||||||
@@ -244,7 +244,7 @@ func (builder *typeBuilder) writeTypedef(typedef *ast.Definition, selectionSet [
|
|||||||
}
|
}
|
||||||
builder.WriteString(")\n")
|
builder.WriteString(")\n")
|
||||||
return nil
|
return nil
|
||||||
case ast.Scalar, ast.Union, ast.Interface:
|
case ast.Scalar, ast.Union:
|
||||||
// TODO(benkraft): Handle custom scalars, unions, and interfaces.
|
// TODO(benkraft): Handle custom scalars, unions, and interfaces.
|
||||||
return fmt.Errorf("not implemented: %v", typedef.Kind)
|
return fmt.Errorf("not implemented: %v", typedef.Kind)
|
||||||
default:
|
default:
|
||||||
|
|||||||
Reference in New Issue
Block a user