Skip to content

Commit 1bae543

Browse files
committed
entgql: ignore the __typename meta-field on fields selection
1 parent 1a350e8 commit 1bae543

File tree

7 files changed

+94
-0
lines changed

7 files changed

+94
-0
lines changed

entgql/internal/todo/ent/gql_collection.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

entgql/internal/todo/todo_test.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2275,6 +2275,71 @@ func TestFieldSelection(t *testing.T) {
22752275
"SELECT `categories`.`id`, `categories`.`text` FROM `categories` WHERE `categories`.`id` IN (?, ?, ?, ?)",
22762276
}, rec.queries)
22772277

2278+
var (
2279+
// language=GraphQL
2280+
query3 = `query {
2281+
todos {
2282+
edges {
2283+
node {
2284+
__typename
2285+
text
2286+
}
2287+
}
2288+
}
2289+
}`
2290+
rsp3 struct {
2291+
Todos struct {
2292+
Edges []struct {
2293+
Node struct {
2294+
TypeName string `json:"__typename"`
2295+
Text string
2296+
}
2297+
}
2298+
}
2299+
}
2300+
)
2301+
rec.reset()
2302+
client.New(handler.NewDefaultServer(gen.NewSchema(ec))).
2303+
MustPost(query3, &rsp3)
2304+
require.Equal(t, []string{
2305+
// Ignore the __typename meta field.
2306+
"SELECT `todos`.`id`, `todos`.`text` FROM `todos` ORDER BY `todos`.`id`",
2307+
}, rec.queries)
2308+
2309+
var (
2310+
// language=GraphQL
2311+
query4 = `query {
2312+
todos {
2313+
edges {
2314+
node {
2315+
text
2316+
extendedField
2317+
}
2318+
}
2319+
}
2320+
}`
2321+
rsp4 struct {
2322+
Todos struct {
2323+
Edges []struct {
2324+
Node struct {
2325+
Text string
2326+
ExtendedField string
2327+
}
2328+
}
2329+
}
2330+
}
2331+
)
2332+
rec.reset()
2333+
client.New(handler.NewDefaultServer(gen.NewSchema(ec))).
2334+
MustPost(query4, &rsp4)
2335+
require.Equal(t, []string{
2336+
// Unknown fields enforce query all columns.
2337+
"SELECT `todos`.`id`, `todos`.`created_at`, `todos`.`status`, " +
2338+
"`todos`.`priority`, `todos`.`text`, `todos`.`blob`, " +
2339+
"`todos`.`category_id`, `todos`.`init`, `todos`.`custom`, " +
2340+
"`todos`.`customp` FROM `todos` ORDER BY `todos`.`id`",
2341+
}, rec.queries)
2342+
22782343
rootO2M := ec.OneToMany.CreateBulk(
22792344
ec.OneToMany.Create().SetName("t0.1"),
22802345
ec.OneToMany.Create().SetName("t0.2"),

entgql/internal/todofed/ent/gql_collection.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

entgql/internal/todogotype/ent/gql_collection.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

entgql/internal/todopulid/ent/gql_collection.go

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

entgql/internal/todouuid/ent/gql_collection.go

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

entgql/template/collection.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ func ({{ $receiver }} *{{ $query }}) collectField(ctx context.Context, opCtx *gr
161161
case {{ range $i, $m := . }}{{ if $i }}, {{ end }}"{{ $m }}"{{ end }}:
162162
{{- end }}
163163
{{- end -}}
164+
case "__typename":
164165
default:
165166
unknownSeen = true
166167
{{- end }}

0 commit comments

Comments
 (0)