olragon / graphql_api

GraphQL for Drupal 7
GNU General Public License v2.0
13 stars 3 forks source link

Error on /graphql 'Try to resolve interface to object' #12

Closed d0t15t closed 6 years ago

d0t15t commented 6 years ago

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

olragon commented 6 years ago

What is field type of field_country?

d0t15t commented 6 years ago

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.

olragon commented 6 years ago

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:

d0t15t commented 6 years ago

Thanks! I'll try it right now.

d0t15t commented 6 years ago

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')
            ),
          );
        }
      )),
    ),
  );
}
olragon commented 6 years ago

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')
            ),
          );
        }
      )),
    ),
  );
}
d0t15t commented 6 years ago

I should have thought of that! Unfortunately though, that doesn't resolve the problem.

d0t15t commented 6 years ago

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!

d0t15t commented 6 years ago

fhp_dd_8083_graphql

olragon commented 6 years ago

I have just merge Github code with internal code. Please update (branch master or 7.x-2.x)

d0t15t commented 6 years ago

It works!

d0t15t commented 6 years ago

Thanks so much! : )

Jehu commented 6 years ago

yeah! many thanks @olragon