From 3d815d9124c887680d26f4efde996ee67c281523 Mon Sep 17 00:00:00 2001 From: Ruud Kamphuis Date: Mon, 14 Aug 2023 11:45:51 +0200 Subject: [PATCH] Add test for multiple schema's with custom int type --- tests/MultipleSchemaTest.php | 53 ++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 tests/MultipleSchemaTest.php diff --git a/tests/MultipleSchemaTest.php b/tests/MultipleSchemaTest.php new file mode 100644 index 000000000..a289aa20a --- /dev/null +++ b/tests/MultipleSchemaTest.php @@ -0,0 +1,53 @@ +createSchema(); + $result1 = GraphQL::executeQuery($schema1, '{ count }'); + self::assertSame(['data' => ['count' => 1]], $result1->toArray()); + + $schema2 = $this->createSchema(); + $result2 = GraphQL::executeQuery($schema2, '{ count }'); + self::assertSame(['data' => ['count' => 1]], $result2->toArray()); + + self::assertNotSame($schema1->getType('Int'), $schema2->getType('Int')); + } + + private function createSchema() : Schema + { + $typeRegistry = new DefaultStandardTypeRegistry( + CustomIntType::class + ); + + $query = new ObjectType([ + 'name' => 'Query', + 'fields' => [ + 'count' => [ + 'type' => Type::nonNull($typeRegistry->int()), + 'resolve' => fn() => 1, + ], + ], + ]); + + $config = SchemaConfig::create([ + 'typeRegistry' => $typeRegistry, + 'query' => $query, + ]); + + return new Schema($config) ; + } +}