Skip to content

Commit

Permalink
test(graphql): Ensure that generated schemas is valid.
Browse files Browse the repository at this point in the history
  • Loading branch information
LastDragon-ru committed Mar 13, 2024
1 parent ee41b8c commit 95c540c
Show file tree
Hide file tree
Showing 32 changed files with 206 additions and 1,461 deletions.
25 changes: 12 additions & 13 deletions packages/graphql/src/SearchBy/Directives/DirectiveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use GraphQL\Language\Parser;
use GraphQL\Type\Definition\EnumType;
use GraphQL\Type\Definition\InputObjectType;
use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\Type;
use Illuminate\Container\Container;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
Expand Down Expand Up @@ -113,9 +114,8 @@ public function testManipulateArgDefinition(string $expected, string $graphql, ?
self::getTestData()->file($graphql),
);

self::assertGraphQLSchemaEquals(
new GraphQLExpected(self::getTestData()->file($expected)),
);
$this->assertGraphQLSchemaEquals(self::getTestData()->file($expected));
$this->assertGraphQLSchemaValid();
}

#[RequiresLaravelScout]
Expand All @@ -133,16 +133,15 @@ public function testManipulateArgDefinitionScoutBuilder(): void {
self::getTestData()->file('Scout.schema.graphql'),
);

self::assertGraphQLSchemaEquals(
new GraphQLExpected(
static::getTestData()->file(
match (true) {
(new RequiresLaravelScout('>=10.3.0'))->isSatisfied() => 'Scout.expected.v10.3.0.graphql',
default => 'Scout.expected.graphql',
},
),
$this->assertGraphQLSchemaEquals(
static::getTestData()->file(
match (true) {
(new RequiresLaravelScout('>=10.3.0'))->isSatisfied() => 'Scout.expected.v10.3.0.graphql',
default => 'Scout.expected.graphql',
},
),
);
$this->assertGraphQLSchemaValid();
}

/**
Expand Down Expand Up @@ -174,7 +173,7 @@ public function testManipulateArgDefinitionScoutBuilderV5Compat(): void {
self::getTestData()->file('V5CompatScout.schema.graphql'),
);

self::assertGraphQLSchemaEquals(
$this->assertGraphQLSchemaEquals(
new GraphQLExpected(
static::getTestData()->file('V5CompatScout.expected.graphql'),
),
Expand Down Expand Up @@ -733,7 +732,7 @@ static function (): void {
'type' => Type::nonNull(Type::string()),
],
],
]) extends InputObjectType implements Ignored {
]) extends ObjectType implements Ignored {
// empty
},
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,6 @@ enum SearchByTypeFlag {
)
}

input Comment {
date: Date
text: String!

user: User
@belongsTo
}

"""
Available conditions for `input CommentsQuery` (only one field allowed at a time).
"""
Expand Down Expand Up @@ -614,6 +606,14 @@ scalar Date
class: "Nuwave\\Lighthouse\\Schema\\Types\\Scalars\\Date"
)

type Comment {
date: Date
text: String!

user: User
@belongsTo
}

type Query {
comments(
where: SearchByRootCommentsQuery
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type User {
name: String!
}

input Comment {
type Comment {
text: String!
user: User @belongsTo
date: Date
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,28 +194,6 @@ enum SearchByTypeFlag {
)
}

input A {
field: B!
fields: [B!]!

"""
Description should be copied.
"""
id: ID!

name: String!
}

input B {
"""
Description should be copied.
"""
id: ID!

name: String
parent: A!
}

"""
Available conditions for `input A` (only one field allowed at a time).
"""
Expand Down Expand Up @@ -679,31 +657,6 @@ input SearchByTypeRangeInt {
min: Int!
}

"""
A paginated list of A items.
"""
type APaginator
@model(
class: "LastDragon_ru\\LaraASP\\GraphQL\\Testing\\Package\\Data\\Models\\TestObject"
)
{
"""
A list of A items.
"""
data: [A!]!
@field(
resolver: "Nuwave\\Lighthouse\\Pagination\\PaginatorField@dataResolver"
)

"""
Pagination information about the list of items.
"""
paginatorInfo: PaginatorInfo!
@field(
resolver: "Nuwave\\Lighthouse\\Pagination\\PaginatorField@paginatorInfoResolver"
)
}

"""
Information about pagination using a fully featured paginator.
"""
Expand Down Expand Up @@ -769,8 +722,33 @@ type Query {
The offset from which items are returned.
"""
page: Int
): APaginator!
): StringPaginator!
@paginate(
model: "LastDragon_ru\\LaraASP\\GraphQL\\Testing\\Package\\Data\\Models\\TestObject"
)
}

"""
A paginated list of String items.
"""
type StringPaginator
@model(
class: "LastDragon_ru\\LaraASP\\GraphQL\\Testing\\Package\\Data\\Models\\TestObject"
)
{
"""
A list of String items.
"""
data: [String!]!
@field(
resolver: "Nuwave\\Lighthouse\\Pagination\\PaginatorField@dataResolver"
)

"""
Pagination information about the list of items.
"""
paginatorInfo: PaginatorInfo!
@field(
resolver: "Nuwave\\Lighthouse\\Pagination\\PaginatorField@paginatorInfoResolver"
)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
type Query {
a(where: A @searchBy): ID! @all
b(where: A @searchBy): [A!]! @paginate(
b(where: A @searchBy): [String!]! @paginate(
model: "LastDragon_ru\\LaraASP\\GraphQL\\Testing\\Package\\Data\\Models\\TestObject"
)
}
Expand All @@ -18,5 +18,5 @@ input B {
"Description should be copied."
id: ID!
name: String
parent: A!
parent: A
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,37 +38,6 @@ enum IgnoredEnum
One
}

input A {
"""
Not ignored
"""
a: String!

b: [String!]!

"""
Marked by @searchByIgnored
"""
c: IgnoredInput!

d: IgnoredDate!
e: [IgnoredDate!]!
f: IgnoredEnum!

g: String
@searchByIgnored
}

input IgnoredInput
@searchByIgnored
{
id: ID
}

input IgnoredType {
name: String!
}

"""
Available conditions for `input A` (only one field allowed at a time).
"""
Expand Down Expand Up @@ -185,6 +154,10 @@ scalar IgnoredDate
)
@searchByIgnored

type IgnoredType {
name: String!
}

type ObjectA {
id: ID!
}
Expand All @@ -197,7 +170,7 @@ type Query {
a(
where: SearchByRootA
@searchBy
): A!
): B!
@all

b(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
type Query {
a(where: A @searchBy): A! @all
a(where: A @searchBy): B! @all
b(where: _ @searchBy): B! @all
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ on
| INPUT_FIELD_DEFINITION
| SCALAR

input A {
id: ID!
}

"""
Available conditions for `input A` (only one field allowed at a time).
"""
Expand Down Expand Up @@ -86,7 +82,7 @@ implements
{
a(
where: SearchByRootA
): A!
): B!

b(
where: SearchByRootB
Expand All @@ -96,7 +92,7 @@ implements
interface QueryInterfaceA {
a(
where: SearchByRootA
): A!
): B!
}

interface QueryInterfaceB {
Expand All @@ -112,11 +108,13 @@ type B {
type Query
implements
& QueryInterface
& QueryInterfaceA
& QueryInterfaceB
{
a(
where: SearchByRootA
@searchBy
): A!
): B!
@all

b(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
type Query implements QueryInterface {
a(where: A @searchBy): A! @all
type Query implements QueryInterface & QueryInterfaceA & QueryInterfaceB {
a(where: A @searchBy): B! @all
b(where: _ @searchBy): B! @all
}

Expand All @@ -12,12 +12,12 @@ type B {
}

interface QueryInterface implements QueryInterfaceA & QueryInterfaceB {
a(where: A): A!
a(where: A): B!
b(where: _): B!
}

interface QueryInterfaceA {
a(where: A): A!
a(where: A): B!
}

interface QueryInterfaceB {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ input SearchByQueryConditionInputA {
}

"""
Available conditions for `input TypeB` (only one field allowed at a time).
Available conditions for `type TypeB` (only one field allowed at a time).
"""
input SearchByQueryConditionTypeB {
"""
Expand Down Expand Up @@ -186,7 +186,7 @@ input SearchByQueryRootInputA {
}

"""
Available conditions for `input TypeB` (only one field allowed at a time).
Available conditions for `type TypeB` (only one field allowed at a time).
"""
input SearchByQueryRootTypeB {
"""
Expand Down Expand Up @@ -409,18 +409,6 @@ input SearchByQueryScalarStringOrNull {
@searchByOperatorStartsWith
}

input TypeA {
child: TypeB!
id: ID!
name: String!
}

input TypeB {
id: ID!
name: String
parent: TypeA!
}

type Query {
a(
where: SearchByQueryRootInputA
Expand All @@ -438,3 +426,15 @@ type Query {
builder: "\\LastDragon_ru\\LaraASP\\GraphQL\\SearchBy\\Directives\\DirectiveTest__QueryBuilderResolver"
)
}

type TypeA {
child: TypeB!
id: ID!
name: String!
}

type TypeB {
id: ID!
name: String
parent: TypeA!
}
Loading

0 comments on commit 95c540c

Please sign in to comment.