Closed d0t15t closed 6 years ago
What is field type of field_country
?
The field is from the Countries module. Country-Objects are Drupal-Entities, however the referencing field is not a basic entity-reference, but instead something specific to the Countries module.
We need define GraphQL object type for this special field type. You can see https://github.com/olragon/graphql_api/blob/master/graphql_api.graphql.inc for reference.
You can declare this field type using these steps:
Thanks! I'll try it right now.
I've implemented the hook in <module>.graphql.inc
, but am not having any luck. Do you have any other suggestions of where else i could look to take clues for debugging? I based my values on countries_entity_info() Thanks so much!
<?php
use GraphQL\Type\Definition\Type;
use GraphQL\Type\Definition\ObjectType;
/**
* Implements hook_graphql_api_info().
*/
function <module>_graphql_api_info() {
return array(
'types' => array(
'field_item_country' => new ObjectType(array(
'name' => 'field_item_country',
'fields' => function () {
$schema = graphql_api();
$file_type = $schema->getObjectType('countries_country');
$t=1;
if (module_exists('countries')) {
$file_type = $schema->getInterfaceType('country');
}
return array(
'cid' => array(
'type' => Type::string(),
'description' => t('Country ID')
),
'iso2' => array(
'type' => Type::string(),
'description' => t('ISO2')
),
'name' => array(
'type' => Type::string(),
'description' => t('Name')
),
);
}
)),
),
);
}
I think Object type name should be field_country
accord to error message.
Could you try this.
<?php
use GraphQL\Type\Definition\Type;
use GraphQL\Type\Definition\ObjectType;
/**
* Implements hook_graphql_api_info().
*/
function <module>_graphql_api_info() {
return array(
'types' => array(
'field_country' => new ObjectType(array(
'name' => 'field_country',
'fields' => function () {
return array(
'cid' => array(
'type' => Type::string(),
'description' => t('Country ID')
),
'iso2' => array(
'type' => Type::string(),
'description' => t('ISO2')
),
'name' => array(
'type' => Type::string(),
'description' => t('Name')
),
);
}
)),
),
);
}
I should have thought of that! Unfortunately though, that doesn't resolve the problem.
I found the $blacklist
variable in Schema.php and tested out adding 'countries' and 'field_country' to the array. For 'countries' it then returns a different error: outputting entity schema-like data of all the entities (see screenshot). I started going through the list, adding each entity-type to the list: 'field_collection_item', 'comment', and so forth. Eventually also 'node' came up, so i guess i won't be able to 'blacklist' it into working. Any clue where this new error is coming from, and why blacklisting 'countries' isn't working? Thanks!
I have just merge Github code with internal code. Please update (branch master or 7.x-2.x)
It works!
Thanks so much! : )
yeah! many thanks @olragon
On the page, it reads out about 100 lines of variables and then the error:
Try to resolve interface to object in field level failed. field_country node