Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when querying via GraphQL #300

Closed
ca-miked opened this issue Sep 13, 2019 · 11 comments
Closed

Error when querying via GraphQL #300

ca-miked opened this issue Sep 13, 2019 · 11 comments

Comments

@ca-miked
Copy link

Description

Getting an error when trying to query a SuperTable field. I have deleted and recreated the field multiple times always resulting in the same error. It looks like GQL support is rather new (#295) so perhaps this is a bug? Thanks for all the efforts on a great plugin btw.

Steps to reproduce

  1. Create a SuperTable field type
  2. Add more than one field within the table
  3. Query field via GQL

Additional info

  • Plugin version: 2.3.0
  • Craft version: 3.3.3

Error Output

Schema must contain unique named types but contains multiple types named "myFieldName_BlockType". Make sure that resolveType function of abstract type "myFieldName_SuperTableField" returns the same type instance as referenced anywhere else within the schema (see http://webonyx.github.io/graphql-php/type-system/#type-registry).

@djurdjen
Copy link

djurdjen commented Sep 16, 2019

Thanks for the great plugin first of all!
I experience the same issue. Is there perhaps any kind of workaround that can be used in the meantime?

Plugin version: 2.3.0
Craft version: 3.3.3

@engram-design
Copy link
Member

Can either of you let me know what you're querying with, just so I can check things on my end?

@CosAnca
Copy link

CosAnca commented Sep 24, 2019

@engram-design Getting the same error for one of my projects as well.

Steps to reproduce

  1. Create a Matrix field type
  2. Create a block that contains multiple fields, one being a SuperTable type field (Blurb in my case)
  3. Create multiple various type fields within the SuperTable field (Blurb)
  4. On an entry page create one or more Blurbs
  5. Querying with the following will throw error
{
  entries(section:"work") {
    title
    ...on work_caseStudy_Entry {
      contentBlocks {
        __typename
        ...on contentBlocks_blurbBlock_BlockType {
          sectionIntro
          multicolumn
          blurb {
            ...on blurb_BlockType {
              blurbTitle
            }
          }
        }
      }
    }
  }
}

Error output

Schema must contain unique named types but contains multiple types named "blurb_BlockType". Make sure that resolveType function of abstract type "blurb_SuperTableField" returns the same type instance as referenced anywhere else within the schema (see http://webonyx.github.io/graphql-php/type-system/#type-registry).

Additional info

  • CraftCMS version: 3.3.4.1
  • Plugin version: 2.3.0

Screenshots of the actual block structure, GQL query and output
Block structure screenshot
GQL query and output screenshot

@sgtpenguin
Copy link

I had this problem too. Found this in a similar issue with Neo. It works!

If you're seeing an error like: Schema must contain unique named types but contains multiple types named..., add the below to the query.

__schema {
    types {
        name
        description
    }
}

For some reason when updating from craft 3.3.2 -> latest, it creates that error. Adding the above, query and then removing fixes it.

spicywebau/craft-neo#252 (comment)

@mattstein
Copy link

mattstein commented Sep 29, 2019

@sgtpenguin This works for me when querying directly on Craft's GraphQL endpoint, but __schema doesn't seem to be available to query for Gatsby's gatsby-source-graphql sources. The same query results in Cannot query field "__schema" on type "CraftGQL".

@ccchapman
Copy link

ccchapman commented Oct 1, 2019

I am having the same issue as @mattstein.

This is due to a change in Craft 3.3.3.

-            $devMode = Craft::$app->getConfig()->getGeneral()->devMode;
-            $schemaDef = $gqlService->getSchemaDef($schema, $devMode);
+            $schemaDef = $gqlService->getSchemaDef($schema, StringHelper::contains($query, '__schema'));

You can see that Craft previously returned the full schema when the site was in devMode. Now, it only returns the full schema when __schema is in the query.

I do not know what the proper solution is here. Any thoughts?

cc: @andris-sevcenko @brandonkelly

@mattstein
Copy link

mattstein commented Oct 1, 2019

I can't figure out how to modify gatsby-source-graphql to always include __schema in its queries or whether this is ultimately a Craft or a Gatsby issue.

What's interesting is that this doesn't seem to be a problem for Matrix blocks, but only for Super Table blocks (and presumably any third-party unions?).

@dangayle
Copy link

dangayle commented Oct 8, 2019

A fix for this is upstream, but needs attention on the plugin side to implement: craftcms/cms#5067

@wfendler
Copy link

I've read through this issue and the Craft issue a couple times but can't quite tell. Is this something we're waiting on a fix from Craft or does this plugin need updating to fix this?

Gatsby doesn't pull in __schema so I'm unable to use the workaround that works on the GraphQL explore page.

@mattstein
Copy link

mattstein commented Oct 22, 2019

@wfendler I believe each plugin author has to implement the fix, including Josh + Super Table, and I'm still patching Craft as of 3.3.11 to get around this.

diff --git a/src/controllers/GraphqlController.php b/src/controllers/GraphqlController.php
index ad7641af80..4666ed4a71 100644
--- a/src/controllers/GraphqlController.php
+++ b/src/controllers/GraphqlController.php
@@ -140,7 +140,7 @@ class GraphqlController extends Controller
         }
 
         try {
-            $schemaDef = $gqlService->getSchemaDef($schema, StringHelper::contains($query, '__schema'));
+            $schemaDef = $gqlService->getSchemaDef($schema, true);
             $result = $gqlService->executeQuery($schemaDef, $query, $variables, $operationName);
         } catch (\Throwable $e) {
             Craft::$app->getErrorHandler()->logException($e);

From what I can tell, this line needs to return $value->getGqlTypeName();, but I'm not sure if that'd have more implications for the codebase.

@engram-design
Copy link
Member

Should be fixed in 2.3.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants