File tree 4 files changed +63
-2
lines changed
4 files changed +63
-2
lines changed Original file line number Diff line number Diff line change 13
13
* @GraphQLField(
14
14
* id = "example_url_route",
15
15
* name = "route",
16
- * type = "Url ",
16
+ * type = "GenericUrl ",
17
17
* nullable = true,
18
18
* arguments = {
19
19
* "path" = "String"
Original file line number Diff line number Diff line change 18
18
* name = "pageTitle",
19
19
* nullable = true,
20
20
* multi = false,
21
- * types = {"Url "}
21
+ * types = {"GenericUrl "}
22
22
* )
23
23
*/
24
24
class PageTitle extends FieldPluginBase {
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Drupal \graphql_example \Plugin \GraphQL \Interfaces ;
4
+
5
+ use Drupal \Core \Url ;
6
+ use Drupal \graphql_core \Annotation \GraphQLInterface ;
7
+ use Drupal \graphql_core \GraphQL \InterfacePluginBase ;
8
+
9
+ /**
10
+ * Common interface for internal and external Urls.
11
+ *
12
+ * For simplicity reasons, this example does not utilize dependency injection.
13
+ *
14
+ * @GraphQLInterface(
15
+ * id = "generic_url",
16
+ * name = "GenericUrl"
17
+ * )
18
+ */
19
+ class GenericUrl extends InterfacePluginBase {
20
+
21
+ /**
22
+ * {@inheritdoc}
23
+ */
24
+ public function resolveType ($ object ) {
25
+ if ($ object instanceof Url) {
26
+ /** @var \Drupal\graphql_core\GraphQLSchemaManagerInterface $schemaManager */
27
+ $ schemaManager = \Drupal::service ('graphql_core.schema_manager ' );
28
+ if ($ object ->isExternal ()) {
29
+ return $ schemaManager ->findByName ('ExternalUrl ' , [
30
+ GRAPHQL_CORE_TYPE_PLUGIN ,
31
+ ]);
32
+ }
33
+ else {
34
+ return $ schemaManager ->findByName ('Url ' , [
35
+ GRAPHQL_CORE_TYPE_PLUGIN ,
36
+ ]);
37
+ }
38
+ }
39
+ }
40
+
41
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Drupal \graphql_example \Plugin \GraphQL \Types ;
4
+
5
+
6
+ use Drupal \graphql_core \Annotation \GraphQLType ;
7
+ use Drupal \graphql_core \GraphQL \TypePluginBase ;
8
+
9
+ /**
10
+ * GraphQL Type for external urls.
11
+ *
12
+ * @GraphQLType(
13
+ * id = "external_url",
14
+ * name = "ExternalUrl",
15
+ * interfaces = {"GenericUrl"}
16
+ * )
17
+ */
18
+ class ExternalUrl extends TypePluginBase {
19
+
20
+ }
You can’t perform that action at this time.
0 commit comments