Skip to content

Commit

Permalink
Merge pull request #244 from proto-graphql/izumin5210/import-from-sam…
Browse files Browse the repository at this point in the history
…e-pkg

Add test for importing types from the same package
  • Loading branch information
izumin5210 authored Dec 15, 2022
2 parents 4817b73 + 3a77c7f commit 3fa4504
Show file tree
Hide file tree
Showing 24 changed files with 732 additions and 2 deletions.
3 changes: 3 additions & 0 deletions e2e/tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
"tests": [
{ "target": "nexus", "proto": { "package": "deprecation", "lib": "google-protobuf" } },
{ "target": "nexus", "proto": { "package": "deprecation", "lib": "protobufjs" } },
{ "target": "nexus", "proto": { "package": "edgecases/import_from_same_pkg", "lib": "google-protobuf" } },
{ "target": "nexus", "proto": { "package": "edgecases/import_from_same_pkg", "lib": "protobufjs" } },
{ "target": "nexus", "proto": { "package": "edgecases/import_squashed_union", "lib": "google-protobuf" } },
{ "target": "nexus", "proto": { "package": "edgecases/import_squashed_union", "lib": "protobufjs" } },
{ "target": "nexus", "proto": { "package": "empty_types", "lib": "google-protobuf" } },
Expand All @@ -23,6 +25,7 @@
{ "target": "nexus", "proto": { "package": "wktypes", "lib": "google-protobuf" } },
{ "target": "nexus", "proto": { "package": "wktypes", "lib": "protobufjs" } },
{ "target": "pothos", "proto": { "package": "deprecation", "lib": "ts-proto" } },
{ "target": "pothos", "proto": { "package": "edgecases/import_from_same_pkg", "lib": "ts-proto" } },
{ "target": "pothos", "proto": { "package": "edgecases/import_squashed_union", "lib": "ts-proto" } },
{ "target": "pothos", "proto": { "package": "empty_types", "lib": "ts-proto" } },
{ "target": "pothos", "proto": { "package": "enums", "lib": "ts-proto" } },
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { ParentMessage } from "@testapis/node-native/lib/testapis/edgecases/import_from_same_pkg/parent_pb";
import { queryField } from "nexus";
import { makeTestSchema } from "../../src/makeTestSchema";
import * as parentTypes from "../__generated__/nexus/google-protobuf/testapis/edgecases/import_from_same_pkg/parent_pb_nexus";
import * as childTypes from "../__generated__/nexus/google-protobuf/testapis/edgecases/import_from_same_pkg/child_pb_nexus";

const testQuery = queryField("test1", {
type: "ParentMessage",
resolve() {
return new ParentMessage();
},
});

export const schema = makeTestSchema({ rootDir: __dirname, types: [parentTypes, childTypes, testQuery] });
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Code generated by setupTests.mjs. DO NOT EDIT.
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@testapp/*": ["./*"]
}
},
"include": [
"./**/*",
"../../src/**/*",
"../__generated__/nexus/google-protobuf/testapis/edgecases/import_from_same_pkg/**/*"
]
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import * as pbjs from "@testapis/node/lib/testapis/edgecases/import_from_same_pkg";
import { queryField } from "nexus";
import { makeTestSchema } from "../../src/makeTestSchema";
import * as parentTypes from "../__generated__/nexus/protobufjs/testapis/edgecases/import_from_same_pkg/parent_pb_nexus";
import * as childTypes from "../__generated__/nexus/protobufjs/testapis/edgecases/import_from_same_pkg/child_pb_nexus";

const testQuery = queryField("test1", {
type: "ParentMessage",
resolve() {
return new pbjs.testapis.edgecases.import_from_same_pkg.ParentMessage();
},
});

export const schema = makeTestSchema({ rootDir: __dirname, types: [parentTypes, childTypes, testQuery] });
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Code generated by setupTests.mjs. DO NOT EDIT.
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@testapp/*": ["./*"]
}
},
"include": [
"./**/*",
"../../src/**/*",
"../__generated__/nexus/protobufjs/testapis/edgecases/import_from_same_pkg/**/*"
]
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import SchemaBuilder from "@pothos/core";

export const builder = new SchemaBuilder({});
builder.queryType({});
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { graphql } from "graphql";
import { schema } from "./schema";

it("processes a query successfully", async () => {
const resp = await graphql(
schema,
/* GraphQL */ `
query Test {
test {
child {
body
}
}
}
`
);
expect(resp).toMatchInlineSnapshot(`
Object {
"data": Object {
"test": Object {
"child": Object {
"body": "hello",
},
},
},
}
`);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { ParentMessage } from "@testapis/ts-proto/lib/testapis/edgecases/import_from_same_pkg/parent";
import { printGraphqlSchema } from "../../src/printGraphqlSchema";
import { ParentMessage$Ref } from "../__generated__/pothos/ts-proto/testapis/edgecases/import_from_same_pkg/parent.pb.pothos";
import { builder } from "./builder";

builder.queryField("test", (t) =>
t.field({
type: ParentMessage$Ref,
resolve() {
return ParentMessage.fromPartial({
child: {
body: "hello",
},
});
},
})
);

export const schema = builder.toSchema();

printGraphqlSchema({ schema, rootDir: __dirname });
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Code generated by setupTests.mjs. DO NOT EDIT.
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@testapp/*": ["./*"]
}
},
"include": [
"./**/*",
"../../src/**/*",
"../__generated__/pothos/ts-proto/testapis/edgecases/import_from_same_pkg/**/*"
]
}
9 changes: 9 additions & 0 deletions e2e/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
{
"path": "tests/nexus--deprecation--protobufjs"
},
{
"path": "tests/nexus--edgecases-import_from_same_pkg--google-protobuf"
},
{
"path": "tests/nexus--edgecases-import_from_same_pkg--protobufjs"
},
{
"path": "tests/nexus--edgecases-import_squashed_union--google-protobuf"
},
Expand Down Expand Up @@ -71,6 +77,9 @@
{
"path": "tests/pothos--deprecation--ts-proto"
},
{
"path": "tests/pothos--edgecases-import_from_same_pkg--ts-proto"
},
{
"path": "tests/pothos--edgecases-import_squashed_union--ts-proto"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
syntax = "proto3";

package testapis.edgecases.import_from_same_pkg;

message ChildMessage {
string body = 1;
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
syntax = "proto3";

package testapis.edgecases.import_from_same_pkg;

import "testapis/edgecases/import_from_same_pkg/child.proto";

message ParentMessage {
testapis.edgecases.import_from_same_pkg.ChildMessage child = 1;
}
Loading

0 comments on commit 3fa4504

Please sign in to comment.