diff --git a/typegate/tests/prisma/mixed_runtime.py b/typegate/tests/prisma/mixed_runtime.py index 57377da2d9..a294532104 100644 --- a/typegate/tests/prisma/mixed_runtime.py +++ b/typegate/tests/prisma/mixed_runtime.py @@ -1,26 +1,35 @@ from typegraph import TypeGraph, effects, policies, t from typegraph.providers.prisma.runtimes.prisma import PrismaRuntime from typegraph.runtimes.graphql import GraphQLRuntime +from typegraph.runtimes.random import RandomMat, RandomRuntime with TypeGraph("prisma") as g: db = PrismaRuntime("prisma", "POSTGRES") - gql = GraphQLRuntime("https://graphqlzero.almansi.me/api") + gql_1 = GraphQLRuntime("https://graphqlzero.almansi.me/api") + rand = RandomRuntime(seed=1) public = policies.public() - country = t.struct( + post = t.struct( { - "code": t.string(), - "name": t.integer(), + "id": t.string(), + "title": t.string(), }, - ).named("Country") + ).named("Post") + user = t.struct( + { + "name": t.string().config(gen="name"), + "age": t.integer().config(gen="age", type="adult"), + } + ).named("Album") record = t.struct( { "id": t.integer().config("id", "auto"), "description": t.string(), - "country": gql.query( - t.struct({"code": t.string()}), - t.optional(country), + "post": gql_1.query( + t.struct({"id": t.string()}), + t.optional(post), ), + "user": t.gen(user, RandomMat(runtime=rand)), }, ).named("Record") diff --git a/typegate/tests/prisma/mixed_runtime_test.ts b/typegate/tests/prisma/mixed_runtime_test.ts index 9d6d44d30a..9b5a87c8b6 100644 --- a/typegate/tests/prisma/mixed_runtime_test.ts +++ b/typegate/tests/prisma/mixed_runtime_test.ts @@ -9,12 +9,13 @@ test("prisma mixed runtime", async (t) => { "postgresql://postgres:password@localhost:5432/db?schema=test", }, }); + await t.should("drop schema and recreate", async () => { await gql` - mutation a { - dropSchema - } - ` + mutation a { + dropSchema + } + ` .expectData({ dropSchema: 0, }) @@ -26,19 +27,19 @@ test("prisma mixed runtime", async (t) => { "insert a record without considering fields owned by other runtimes", async () => { await gql` - mutation { - createOneRecord ( - data: { - id: 1, - description: "Some description" - } - ) - { - id - description - } + mutation { + createOneRecord ( + data: { + id: 1, + description: "Some description" + } + ) + { + id + description } - `.expectData({ + } + `.expectData({ createOneRecord: { id: 1, description: "Some description", @@ -48,38 +49,67 @@ test("prisma mixed runtime", async (t) => { }, ); - // At this point, mixed runtime should work fine + await t.should("work with different runtimes", async () => { + await gql` + query { + findUniqueRecord(where: { + id: 1 + }) { + id + description + post(id: "1") { + id + title + } + } + } + `.expectData({ + findUniqueRecord: { + id: 1, + description: "Some description", + post: { + id: "1", + title: + "sunt aut facere repellat provident occaecati excepturi optio reprehenderit", + }, + }, + }) + .on(e); + }); - // graphql runtime bug ? - // generated sub-query: - // query Q { - // country { - // code - // name - // } - // } - // request err: Error: From remote graphql: Cannot query field "country" on type "Query". - // await t.should("find unique and work with graphql runtime", async () => { - // await gql` - // query { - // findUniqueRecord(where: { - // id: 1 - // }) { - // id - // description - // country(code: "MC") { - // code - // name - // } - // } - // } - // `.expectData({ - // findUniqueRecord: { - // id: 1, - // description: "Some description", - // country: { code: "MC", name: "Monaco" }, - // }, - // }) - // .on(e); - // }); + await t.should( + "work with more than two runtimes", + async () => { + await gql` + query { + findUniqueRecord(where: { + id: 1 + }) { + id + description + post(id: "1") { + id + title + } + user { + name + age + } + } + } + `.expectData({ + findUniqueRecord: { + id: 1, + description: "Some description", + post: { + id: "1", + title: + "sunt aut facere repellat provident occaecati excepturi optio reprehenderit", + }, + user: { name: "Landon Glover", age: 62 }, + }, + }) + .on(e); + }, + ); }); diff --git a/typegraph/typegraph/providers/prisma/type_generator.py b/typegraph/typegraph/providers/prisma/type_generator.py index e3e4509cb2..91f6c11ab0 100644 --- a/typegraph/typegraph/providers/prisma/type_generator.py +++ b/typegraph/typegraph/providers/prisma/type_generator.py @@ -83,7 +83,7 @@ def get_out_type( return proxy if isinstance(tpe, t.func): - return self.get_out_type(tpe.out) + return tpe.out if not isinstance(tpe, t.struct): return tpe