-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MET-128: either should be supported in the introspection (#243)
* init tests * current wip * union => input object * make recursive call * add either/union in visitor * fix tree-view * add proper test * remove comment * update snapshots * merge fields * fix empty object * regenerate snapshots * add comment * update snapshot
- Loading branch information
1 parent
97ddb03
commit 2b86c1e
Showing
17 changed files
with
1,555 additions
and
968 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
typegate/tests/introspection/__snapshots__/union_either_test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
export const snapshot = {}; | ||
|
||
snapshot[`Basic introspection 1`] = ` | ||
{ | ||
__schema: { | ||
types: [ | ||
{ | ||
fields: null, | ||
kind: "SCALAR", | ||
name: "String", | ||
}, | ||
{ | ||
fields: null, | ||
kind: "SCALAR", | ||
name: "Int", | ||
}, | ||
{ | ||
fields: [ | ||
{ | ||
name: "test", | ||
}, | ||
], | ||
kind: "OBJECT", | ||
name: "Query", | ||
}, | ||
{ | ||
fields: [ | ||
{ | ||
name: "favorite", | ||
}, | ||
{ | ||
name: "name", | ||
}, | ||
], | ||
kind: "OBJECT", | ||
name: "Output", | ||
}, | ||
{ | ||
fields: [ | ||
{ | ||
name: "ref", | ||
}, | ||
{ | ||
name: "model", | ||
}, | ||
{ | ||
name: "color", | ||
}, | ||
{ | ||
name: "size", | ||
}, | ||
{ | ||
name: "name", | ||
}, | ||
], | ||
kind: "OBJECT", | ||
name: "FavoriteToy", | ||
}, | ||
{ | ||
fields: [ | ||
{ | ||
name: "size", | ||
}, | ||
{ | ||
name: "name", | ||
}, | ||
], | ||
kind: "OBJECT", | ||
name: "Rubix", | ||
}, | ||
{ | ||
fields: [ | ||
{ | ||
name: "color", | ||
}, | ||
], | ||
kind: "OBJECT", | ||
name: "Toygun", | ||
}, | ||
{ | ||
fields: [ | ||
{ | ||
name: "ref", | ||
}, | ||
{ | ||
name: "model", | ||
}, | ||
], | ||
kind: "OBJECT", | ||
name: "Gunpla", | ||
}, | ||
{ | ||
fields: [ | ||
{ | ||
name: "union_1", | ||
}, | ||
{ | ||
name: "union_0", | ||
}, | ||
], | ||
kind: "OBJECT", | ||
name: "union_9", | ||
}, | ||
{ | ||
fields: null, | ||
kind: "INPUT_OBJECT", | ||
name: "FavoriteToyInp", | ||
}, | ||
{ | ||
fields: null, | ||
kind: "INPUT_OBJECT", | ||
name: "RubixInp", | ||
}, | ||
{ | ||
fields: null, | ||
kind: "INPUT_OBJECT", | ||
name: "ToygunInp", | ||
}, | ||
{ | ||
fields: null, | ||
kind: "INPUT_OBJECT", | ||
name: "GunplaInp", | ||
}, | ||
{ | ||
fields: null, | ||
kind: "INPUT_OBJECT", | ||
name: "union_9Inp", | ||
}, | ||
], | ||
}, | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from typegraph import TypeGraph, policies, t | ||
from typegraph.runtimes.deno import PredefinedFunMat | ||
|
||
with TypeGraph("introspect-union-either") as g: | ||
rubix_cube = t.struct({"name": t.string(), "size": t.integer()}).named("Rubix") | ||
toygun = t.struct({"color": t.string()}).named("Toygun") | ||
gunpla = t.struct( | ||
{"model": t.string(), "ref": t.union([t.string(), t.integer()])} | ||
).named("Gunpla") | ||
toy = t.either([rubix_cube, toygun, gunpla]) | ||
|
||
user = t.struct( | ||
{"name": t.string().named("Username"), "favorite": toy.named("FavoriteToy")} | ||
).named("User") | ||
|
||
g.expose( | ||
test=t.func( | ||
user.named("Input"), | ||
user.named("Output"), | ||
PredefinedFunMat("identity"), | ||
) | ||
.named("f") | ||
.add_policy(policies.public()), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright Metatype OÜ under the Elastic License 2.0 (ELv2). See LICENSE.md for usage. | ||
|
||
import { gql, test } from "../utils.ts"; | ||
|
||
// https://github.com/graphql/graphql-js/blob/main/src/__tests__/starWarsIntrospection-test.ts | ||
|
||
test("Basic introspection", async (t) => { | ||
const e = await t.pythonFile("introspection/union_either.py"); | ||
|
||
await t.should("allow querying the schema for query type", async () => { | ||
await gql` | ||
query IntrospectionQuery { | ||
__schema { | ||
types { | ||
name | ||
kind | ||
fields { | ||
name | ||
} | ||
} | ||
} | ||
} | ||
` | ||
.matchSnapshot(t) | ||
.on(e); | ||
}); | ||
}, { introspection: true }); |
Oops, something went wrong.