-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #255 from proto-graphql/izumin5210/proto3-optional
feat: support proto3 optional
- Loading branch information
Showing
25 changed files
with
640 additions
and
2 deletions.
There are no files selected for viewing
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,10 @@ | ||
--- | ||
"@proto-graphql/e2e": patch | ||
"@proto-graphql/codegen-core": patch | ||
"@proto-graphql/proto-descriptors": patch | ||
"@testapis/proto": patch | ||
"protoc-gen-nexus": patch | ||
"protoc-gen-pothos": patch | ||
--- | ||
|
||
support proto3 optional |
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
17 changes: 17 additions & 0 deletions
17
e2e/tests/nexus--proto3_optional--google-protobuf/__generated__/schema.graphql
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
e2e/tests/nexus--proto3_optional--google-protobuf/schema.ts
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,18 @@ | ||
import "@proto-nexus/google-protobuf"; | ||
import { Message } from "@testapis/node-native/lib/testapis/proto3_optional/proto3_optional_pb"; | ||
import { queryField } from "nexus"; | ||
|
||
import { makeTestSchema } from "../../src/makeTestSchema"; | ||
import * as types1 from "../__generated__/nexus/google-protobuf/testapis/proto3_optional/proto3_optional_pb_nexus"; | ||
|
||
const testQuery = queryField("test1", { | ||
type: "Message", | ||
resolve() { | ||
return new Message(); | ||
}, | ||
}); | ||
|
||
export const schema = makeTestSchema({ | ||
rootDir: __dirname, | ||
types: [types1, testQuery], | ||
}); |
17 changes: 17 additions & 0 deletions
17
e2e/tests/nexus--proto3_optional--google-protobuf/tsconfig.json
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,17 @@ | ||
// Code generated by setupTests.mjs. DO NOT EDIT. | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"paths": { | ||
"@testapp/*": [ | ||
"./*" | ||
] | ||
} | ||
}, | ||
"include": [ | ||
"./**/*", | ||
"../../src/**/*", | ||
"../__generated__/nexus/google-protobuf/testapis/proto3_optional/**/*" | ||
] | ||
} |
17 changes: 17 additions & 0 deletions
17
e2e/tests/nexus--proto3_optional--protobufjs/__generated__/schema.graphql
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import "@proto-nexus/google-protobuf"; | ||
import * as pb from "@testapis/node/lib/testapis/proto3_optional"; | ||
import { queryField } from "nexus"; | ||
|
||
import { makeTestSchema } from "../../src/makeTestSchema"; | ||
import * as types1 from "../__generated__/nexus/protobufjs/testapis/proto3_optional/proto3_optional_pb_nexus"; | ||
|
||
const testQuery = queryField("test1", { | ||
type: "Message", | ||
resolve() { | ||
return new pb.testapis.proto3_optional.Message(); | ||
}, | ||
}); | ||
|
||
export const schema = makeTestSchema({ | ||
rootDir: __dirname, | ||
types: [types1, testQuery], | ||
}); |
17 changes: 17 additions & 0 deletions
17
e2e/tests/nexus--proto3_optional--protobufjs/tsconfig.json
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,17 @@ | ||
// Code generated by setupTests.mjs. DO NOT EDIT. | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"paths": { | ||
"@testapp/*": [ | ||
"./*" | ||
] | ||
} | ||
}, | ||
"include": [ | ||
"./**/*", | ||
"../../src/**/*", | ||
"../__generated__/nexus/protobufjs/testapis/proto3_optional/**/*" | ||
] | ||
} |
14 changes: 14 additions & 0 deletions
14
e2e/tests/pothos--proto3_optional--ts-proto/__generated__/schema.graphql
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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({}); |
57 changes: 57 additions & 0 deletions
57
e2e/tests/pothos--proto3_optional--ts-proto/schema.test.ts
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,57 @@ | ||
import { graphql } from "graphql"; | ||
|
||
import { schema } from "./schema"; | ||
|
||
it("processes a query successfully", async () => { | ||
const resp = await graphql({ | ||
schema, | ||
source: /* GraphQL */ ` | ||
query Test { | ||
valuesArePresent { | ||
...Message | ||
} | ||
} | ||
fragment Message on Message { | ||
requiredStringValue | ||
optionalStringValue | ||
} | ||
`, | ||
}); | ||
expect(resp).toMatchInlineSnapshot(` | ||
{ | ||
"data": { | ||
"valuesArePresent": { | ||
"optionalStringValue": "optional field", | ||
"requiredStringValue": "required field", | ||
}, | ||
}, | ||
} | ||
`); | ||
}); | ||
|
||
it("processes a query successfully when values are blank", async () => { | ||
const resp = await graphql({ | ||
schema, | ||
source: /* GraphQL */ ` | ||
query Test { | ||
valuesAreBlank { | ||
...Message | ||
} | ||
} | ||
fragment Message on Message { | ||
requiredStringValue | ||
optionalStringValue | ||
} | ||
`, | ||
}); | ||
expect(resp).toMatchInlineSnapshot(` | ||
{ | ||
"data": { | ||
"valuesAreBlank": { | ||
"optionalStringValue": null, | ||
"requiredStringValue": "", | ||
}, | ||
}, | ||
} | ||
`); | ||
}); |
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,30 @@ | ||
import { Message } from "@testapis/ts-proto/lib/testapis/proto3_optional/proto3_optional"; | ||
|
||
import { printGraphqlSchema } from "../../src/printGraphqlSchema"; | ||
import { Message$Ref } from "../__generated__/pothos/ts-proto/testapis/proto3_optional/proto3_optional.pb.pothos"; | ||
import { builder } from "./builder"; | ||
|
||
builder.queryField("valuesArePresent", (f) => | ||
f.field({ | ||
type: Message$Ref, | ||
resolve() { | ||
return Message.fromPartial({ | ||
requiredStringValue: "required field", | ||
optionalStringValue: "optional field", | ||
}); | ||
}, | ||
}) | ||
); | ||
|
||
builder.queryField("valuesAreBlank", (f) => | ||
f.field({ | ||
type: Message$Ref, | ||
resolve() { | ||
return Message.fromPartial({}); | ||
}, | ||
}) | ||
); | ||
|
||
export const schema = builder.toSchema(); | ||
|
||
printGraphqlSchema({ schema, rootDir: __dirname }); |
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,17 @@ | ||
// Code generated by setupTests.mjs. DO NOT EDIT. | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"paths": { | ||
"@testapp/*": [ | ||
"./*" | ||
] | ||
} | ||
}, | ||
"include": [ | ||
"./**/*", | ||
"../../src/**/*", | ||
"../__generated__/pothos/ts-proto/testapis/proto3_optional/**/*" | ||
] | ||
} |
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
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
Binary file added
BIN
+411 Bytes
packages/@testapis/proto/src/testapis/proto3_optional/descriptor_set.pb
Binary file not shown.
8 changes: 8 additions & 0 deletions
8
packages/@testapis/proto/src/testapis/proto3_optional/proto3_optional.proto
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,8 @@ | ||
syntax = "proto3"; | ||
|
||
package testapis.proto3_optional; | ||
|
||
message Message { | ||
string required_string_value = 1; | ||
optional string optional_string_value = 2; | ||
} |
Oops, something went wrong.