Skip to content

Commit b9c65ea

Browse files
authored
chore: improve repo integration test (#57)
1 parent 4544762 commit b9c65ea

File tree

10 files changed

+104
-16
lines changed

10 files changed

+104
-16
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
run: bun tsc
3030

3131
- name: Unit Tests
32-
run: bun test
32+
run: bun unit
3333

3434
- uses: actions/setup-java@v4
3535
with:

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
*.hbs
2+
test/integration/expected.graphql

build.gradle.kts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,32 @@
1+
import com.expediagroup.graphql.plugin.gradle.graphql
2+
13
repositories {
24
mavenCentral()
35
}
46

57
plugins {
68
kotlin("jvm") version "1.9.23"
9+
id("com.expediagroup.graphql") version "7.1.1"
710
}
811

912
dependencies {
1013
implementation("com.expediagroup", "graphql-kotlin-schema-generator", "7.1.1")
14+
implementation("com.expediagroup", "graphql-kotlin-server", "7.1.1")
1115
implementation("com.expediagroup", "graphql-kotlin-federation", "7.1.1")
1216
}
1317

1418
sourceSets {
15-
test {
19+
main {
1620
kotlin {
17-
srcDirs("test/unit", "test/integration")
21+
srcDirs("test/unit")
1822
exclude("**/actual.kt")
23+
srcDirs("test/integration")
1924
}
2025
}
2126
}
27+
28+
graphql {
29+
schema {
30+
packages = listOf("test.integration")
31+
}
32+
}

codegen.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { GraphQLKotlinCodegenConfig } from "./src/plugin";
2+
import { CodegenConfig } from "@graphql-codegen/cli";
3+
4+
export default {
5+
overwrite: true,
6+
schema: "test/**/*.graphql",
7+
config: {
8+
namingConvention: "keep",
9+
},
10+
generates: {
11+
"test/integration/Types.kt": {
12+
plugins: [
13+
{
14+
"dist/plugin.cjs": {
15+
resolverClasses: [
16+
{
17+
typeName: "Query",
18+
},
19+
],
20+
} satisfies GraphQLKotlinCodegenConfig,
21+
},
22+
],
23+
},
24+
},
25+
} satisfies CodegenConfig;

codegen.yml

Lines changed: 0 additions & 9 deletions
This file was deleted.

docs/docs/recommended-usage.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ import com.types.generated.MyType
5151
import com.types.generated.Query as QueryInterface
5252

5353
class MyQuery : Query, QueryInterface() {
54-
override suspend fun resolveMyType(input: String): MyType =
54+
override fun resolveMyType(input: String): MyType =
5555
MyType(
5656
field1 = myExpensiveCall1(),
5757
field2 = myExpensiveCall2()
@@ -103,7 +103,7 @@ import com.types.generated.MyType as MyTypeInterface
103103
import com.expediagroup.graphql.generator.annotations.GraphQLIgnore
104104

105105
class MyQuery : Query, QueryInterface() {
106-
override suspend fun resolveMyType(input: String): MyType = MyType()
106+
override fun resolveMyType(input: String): MyType = MyType()
107107
}
108108

109109
@GraphQLIgnore

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@
3939
"build": "tsup src/plugin.ts --clean --dts --external graphql",
4040
"format": "prettier --write .",
4141
"format-check": "prettier --check .",
42-
"integration": "bun run build && graphql-codegen && ./gradlew build",
42+
"integration": "bun run build && graphql-codegen && ./gradlew graphqlGenerateSDL && bun test ./test/integration.test.ts",
4343
"lint": "eslint .",
4444
"prepack": "bun run build",
4545
"prepare": "husky",
46-
"test": "bun test"
46+
"unit": "bun test ./test/plugin.test.ts"
4747
},
4848
"type": "module"
4949
}

test/integration.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { describe, expect, it } from "bun:test";
2+
3+
describe("Integration", () => {
4+
it("schema generated by GraphQL Kotlin should match expected", async () => {
5+
const generatedSchema = await Bun.file(
6+
`${process.cwd()}/build/schema.graphql`,
7+
).text();
8+
const expectedSchema = await Bun.file(
9+
`${process.cwd()}/test/integration/expected.graphql`,
10+
).text();
11+
expect(generatedSchema).toBe(expectedSchema);
12+
});
13+
});

test/integration/Query.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package test.integration
2+
3+
import com.expediagroup.graphql.server.operations.Query
4+
import graphql.schema.DataFetchingEnvironment
5+
import test.integration.Query as QueryInterface
6+
7+
class IntegrationTestQuery() : Query, QueryInterface() {
8+
override fun testQuery(dataFetchingEnvironment: DataFetchingEnvironment): SomeType = SomeType()
9+
}

test/integration/expected.graphql

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
schema {
2+
query: Query
3+
}
4+
5+
"Marks the field, argument, input field or enum value as deprecated"
6+
directive @deprecated(
7+
"The reason for the deprecation"
8+
reason: String = "No longer supported"
9+
) on FIELD_DEFINITION | ARGUMENT_DEFINITION | ENUM_VALUE | INPUT_FIELD_DEFINITION
10+
11+
"Directs the executor to include this field or fragment only when the `if` argument is true"
12+
directive @include(
13+
"Included when true."
14+
if: Boolean!
15+
) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
16+
17+
"Indicates an Input Object is a OneOf Input Object."
18+
directive @oneOf on INPUT_OBJECT
19+
20+
"Directs the executor to skip this field or fragment when the `if` argument is true."
21+
directive @skip(
22+
"Skipped when true."
23+
if: Boolean!
24+
) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
25+
26+
"Exposes a URL that specifies the behaviour of this scalar."
27+
directive @specifiedBy(
28+
"The URL that specifies the behaviour of this scalar."
29+
url: String!
30+
) on SCALAR
31+
32+
type Query {
33+
testQuery: SomeType!
34+
}
35+
36+
type SomeType {
37+
someField: String
38+
}

0 commit comments

Comments
 (0)