The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 06:00 UTC
| 1 | /** |
| 2 | * Schema model features the GitHub fixtures lack, plus the newer introspection |
| 3 | * keys read from `test/fixtures/introspection/modern.json`. |
| 4 | */ |
| 5 | import * as IntrospectionReader from "@effect/graphql-generator/internal/IntrospectionReader" |
| 6 | import { assert, describe, it } from "@effect/vitest" |
| 7 | import * as Result from "effect/Result" |
| 8 | import { source } from "./utils/ast.ts" |
| 9 | import { |
| 10 | assertModelsEqual, |
| 11 | assertType, |
| 12 | enumType, |
| 13 | enumValue, |
| 14 | field, |
| 15 | fixture, |
| 16 | inputObjectType, |
| 17 | inputValue, |
| 18 | interfaceType, |
| 19 | list, |
| 20 | named, |
| 21 | nonNull, |
| 22 | objectType, |
| 23 | readIntrospection, |
| 24 | readSdl, |
| 25 | scalarType, |
| 26 | schema, |
| 27 | unionType |
| 28 | } from "./utils/model.ts" |
| 29 | |
| 30 | describe("SdlReader", () => { |
| 31 | it("@oneOf marks an input object", () => { |
| 32 | assertType( |
| 33 | readSdl(fixture("sdl/one-of.graphql")), |
| 34 | inputObjectType("PetBy", [inputValue("id", named("ID")), inputValue("name", named("String"))], { |
| 35 | description: "Exactly one way to identify a pet.", |
| 36 | oneOf: true |
| 37 | }) |
| 38 | ) |
| 39 | }) |
| 40 | |
| 41 | it("input values carry deprecation reasons, defaulting when none is given", () => { |
| 42 | assertType( |
| 43 | readSdl("type Query { a: Int } input I { old: Int @deprecated, legacy: Int @deprecated(reason: \"Use `a`.\") }"), |
| 44 | inputObjectType("I", [ |
| 45 | inputValue("old", named("Int"), { deprecationReason: "No longer supported" }), |
| 46 | inputValue("legacy", named("Int"), { deprecationReason: "Use `a`." }) |
| 47 | ]) |
| 48 | ) |
| 49 | }) |
| 50 | |
| 51 | it("directive definitions and applied directives are dropped", () => { |
| 52 | assertModelsEqual( |
| 53 | readSdl("directive @tag(name: String!) repeatable on OBJECT type Query @tag(name: \"a\") @undeclared { a: Int }"), |
| 54 | schema({ queryType: "Query", types: [objectType("Query", [field("a", named("Int"))])] }) |
| 55 | ) |
| 56 | }) |
| 57 | |
| 58 | it("a type named Subscription is the subscription root when there is no schema definition", () => { |
| 59 | assert.strictEqual(readSdl("type Query { a: Int } type Subscription { b: Int }").subscriptionType, "Subscription") |
| 60 | }) |
| 61 | |
| 62 | it("merges every extend form into its definition in document order", () => { |
| 63 | assertModelsEqual( |
| 64 | readSdl(fixture("sdl/extensions.graphql")), |
| 65 | schema({ |
| 66 | queryType: "Root", |
| 67 | mutationType: "Changes", |
| 68 | types: [ |
| 69 | objectType("Root", [ |
| 70 | field("a", named("String")), |
| 71 | field("items", nonNull(list(nonNull(named("Item")))), { |
| 72 | arguments: [inputValue("filter", named("Filter"))] |
| 73 | }), |
| 74 | field("node", named("Node"), { arguments: [inputValue("id", nonNull(named("ID")))] }) |
| 75 | ]), |
| 76 | interfaceType("Node", [field("id", nonNull(named("ID"))), field("title", named("String"))], { |
| 77 | possibleTypes: ["Film"] |
| 78 | }), |
| 79 | objectType("Book", [field("title", named("String"))]), |
| 80 | objectType("Film", [field("title", named("String")), field("id", nonNull(named("ID")))], { |
| 81 | interfaces: ["Node"] |
| 82 | }), |
| 83 | unionType("Item", ["Book", "Film"]), |
| 84 | enumType("Genre", [enumValue("DRAMA"), enumValue("COMEDY")]), |
| 85 | inputObjectType("Filter", [inputValue("genre", named("Genre")), inputValue("title", named("String"))]), |
| 86 | scalarType("Url"), |
| 87 | |
| 88 | objectType("Changes", [ |
| 89 | field("rename", named("Film"), { arguments: [inputValue("title", nonNull(named("String")))] }) |
| 90 | ]) |
| 91 | ] |
| 92 | }) |
| 93 | ) |
| 94 | }) |
| 95 | }) |
| 96 | |
| 97 | describe("IntrospectionReader", () => { |
| 98 | it("isOneOf and input value deprecation match the SDL they came from", () => { |
| 99 | // modern.json is graphql-js introspection of modern.graphql with every optional key enabled. |
| 100 | assertModelsEqual( |
| 101 | readIntrospection(fixture("introspection/modern.json")), |
| 102 | readSdl(fixture("introspection/modern.graphql")) |
| 103 | ) |
| 104 | }) |
| 105 | |
| 106 | it("accepts the { data: { __schema } } response shape", () => { |
| 107 | const json = fixture("introspection/modern.json") |
| 108 | assertModelsEqual(readIntrospection(`{"data":${json}}`), readIntrospection(json)) |
| 109 | }) |
| 110 | |
| 111 | it("rejects JSON with neither the { __schema } nor the { data: { __schema } } shape", () => { |
| 112 | const result = IntrospectionReader.read(source("{\"schema\":{}}", "bad.json")) |
| 113 | assert(Result.isFailure(result), "expected a diagnostic") |
| 114 | assert.strictEqual(result.failure.path, "bad.json") |
| 115 | }) |
| 116 | }) |