Skip to content

Commit 5a5dfc4

Browse files
authored
Merge pull request #221 from kidunot89/bugfix/id-type-enum-types
Fixes introspection query
2 parents 5e5003b + abeadc8 commit 5a5dfc4

File tree

3 files changed

+146
-5
lines changed

3 files changed

+146
-5
lines changed

includes/type/enum/class-id-type-enums.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,17 @@ public static function register() {
101101
),
102102
)
103103
);
104+
105+
register_graphql_enum_type(
106+
'TaxRateIdTypeEnum',
107+
array(
108+
'description' => __( 'The Type of Identifier used to fetch a single Tax rate. Default is ID.', 'wp-graphql' ),
109+
'values' => array(
110+
'id' => self::get_value( 'id' ),
111+
'database_id' => self::get_value( 'database_id' ),
112+
),
113+
)
114+
);
104115
}
105116

106117
/**

includes/type/object/class-coupon-type.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,7 @@ public static function register() {
119119
'type' => 'Coupon',
120120
'description' => __( 'A coupon object', 'wp-graphql-woocommerce' ),
121121
'args' => array(
122-
'id' => array(
123-
'type' => array(
124-
'non_null' => 'ID',
125-
),
126-
),
122+
'id' => array( 'type' => array( 'non_null' => 'ID' ) ),
127123
'idType' => array(
128124
'type' => 'CouponIdTypeEnum',
129125
'description' => __( 'Type of ID being used identify coupon', 'wp-graphql-woocommerce' ),
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
<?php
2+
3+
class IntrospectionQueryTest extends \Codeception\TestCase\WPTestCase
4+
{
5+
6+
public function setUp() {
7+
// before
8+
parent::setUp();
9+
10+
// your set up methods here
11+
}
12+
13+
public function tearDown() {
14+
// your tear down methods here
15+
16+
// then
17+
parent::tearDown();
18+
}
19+
20+
// Validate schema.
21+
public function testSchema() {
22+
try {
23+
$request = new \WPGraphQL\Request();
24+
$request->schema->assertValid();
25+
26+
// Assert true upon success.
27+
$this->assertTrue( true );
28+
} catch (\GraphQL\Error\InvariantViolation $e) {
29+
// use --debug flag to view.
30+
codecept_debug( $e->getMessage() );
31+
32+
// Fail upon throwing
33+
$this->assertTrue( false );
34+
}
35+
}
36+
37+
// Test introspection query.
38+
public function testIntrospectionQuery() {
39+
$query = '
40+
query IntrospectionQuery {
41+
__schema {
42+
queryType { name }
43+
mutationType { name }
44+
subscriptionType { name }
45+
types {
46+
...FullType
47+
}
48+
directives {
49+
name
50+
description
51+
locations
52+
args {
53+
...InputValue
54+
}
55+
}
56+
}
57+
}
58+
fragment FullType on __Type {
59+
kind
60+
name
61+
description
62+
fields(includeDeprecated: true) {
63+
name
64+
description
65+
args {
66+
...InputValue
67+
}
68+
type {
69+
...TypeRef
70+
}
71+
isDeprecated
72+
deprecationReason
73+
}
74+
inputFields {
75+
...InputValue
76+
}
77+
interfaces {
78+
...TypeRef
79+
}
80+
enumValues(includeDeprecated: true) {
81+
name
82+
description
83+
isDeprecated
84+
deprecationReason
85+
}
86+
possibleTypes {
87+
...TypeRef
88+
}
89+
}
90+
fragment InputValue on __InputValue {
91+
name
92+
description
93+
type { ...TypeRef }
94+
defaultValue
95+
}
96+
fragment TypeRef on __Type {
97+
kind
98+
name
99+
ofType {
100+
kind
101+
name
102+
ofType {
103+
kind
104+
name
105+
ofType {
106+
kind
107+
name
108+
ofType {
109+
kind
110+
name
111+
ofType {
112+
kind
113+
name
114+
ofType {
115+
kind
116+
name
117+
ofType {
118+
kind
119+
name
120+
}
121+
}
122+
}
123+
}
124+
}
125+
}
126+
}
127+
}
128+
';
129+
130+
$results = graphql( array( 'query' => $query ) );
131+
132+
$this->assertArrayNotHasKey('errors', $results );
133+
}
134+
}

0 commit comments

Comments
 (0)