allow interface{} as a scalar
This commit is contained in:
@@ -74,6 +74,7 @@ func TestGenerate(t *testing.T) {
|
||||
Scalars: map[string]string{
|
||||
"ID": "github.com/me/mypkg.ID",
|
||||
"DateTime": "time.Time",
|
||||
"Junk": "interface{}",
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
+6
-1
@@ -39,7 +39,12 @@ func (g *generator) ref(fullyQualifiedName string) (qualifiedName string, err er
|
||||
func (g *generator) getRef(fullyQualifiedName string, addImport bool) (qualifiedName string, err error) {
|
||||
i := strings.LastIndex(fullyQualifiedName, ".")
|
||||
if i == -1 {
|
||||
if types.Universe.Lookup(fullyQualifiedName) == nil {
|
||||
// We allow any builtin type, or interface{}. In principle it would be
|
||||
// fine to allow any interface or struct, but (1) they might refer to a
|
||||
// type that needs an import, and (2) that just honestly seems
|
||||
// confusing, why would you want it. But the empty interface,
|
||||
// specifically, is useful.
|
||||
if fullyQualifiedName != "interface{}" && types.Universe.Lookup(fullyQualifiedName) == nil {
|
||||
return "", fmt.Errorf(
|
||||
`unknown name "%v"; expected a builtin or path/to/package.Name`, fullyQualifiedName)
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
query EmptyInterface { getJunk }
|
||||
@@ -0,0 +1,29 @@
|
||||
package test
|
||||
|
||||
// Code generated by github.com/Khan/genqlient, DO NOT EDIT.
|
||||
|
||||
import (
|
||||
"github.com/Khan/genqlient/graphql"
|
||||
)
|
||||
|
||||
type EmptyInterfaceResponse struct {
|
||||
GetJunk interface{} `json:"getJunk"`
|
||||
}
|
||||
|
||||
func EmptyInterface(
|
||||
client graphql.Client,
|
||||
) (*EmptyInterfaceResponse, error) {
|
||||
var retval EmptyInterfaceResponse
|
||||
err := client.MakeRequest(
|
||||
nil,
|
||||
"EmptyInterface",
|
||||
`
|
||||
query EmptyInterface {
|
||||
getJunk
|
||||
}
|
||||
`,
|
||||
&retval,
|
||||
nil,
|
||||
)
|
||||
return &retval, err
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"operations": [
|
||||
{
|
||||
"operationName": "EmptyInterface",
|
||||
"query": "\nquery EmptyInterface {\n\tgetJunk\n}\n",
|
||||
"sourceLocation": "testdata/queries/EmptyInterface.graphql"
|
||||
}
|
||||
]
|
||||
}
|
||||
+3
@@ -1,5 +1,7 @@
|
||||
scalar DateTime
|
||||
|
||||
scalar Junk
|
||||
|
||||
enum Role {
|
||||
STUDENT
|
||||
TEACHER
|
||||
@@ -64,6 +66,7 @@ type Query {
|
||||
randomLeaf: LeafContent!
|
||||
convert(dt: DateTime!, tz: String): DateTime!
|
||||
maybeConvert(dt: DateTime, tz: String): DateTime
|
||||
getJunk: Junk
|
||||
}
|
||||
|
||||
type Mutation {
|
||||
|
||||
Reference in New Issue
Block a user