-
Notifications
You must be signed in to change notification settings - Fork 639
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
GraphQL third-party schemas not generated properly #5067
Comments
I ended up doing the patch like Matt suggested, worked. I was trying to query Neo fields from Gatsby, and I had all the same errors he mentioned. |
That patch will work, but it will also impact the performance of the site, especially as the site grows more complex. We added a workaround/hack for Matrix (f4b60b6), but that was one day before the conference, so it was really more of a "just get this in because we need something" fix. I'll see if I can add a better fix or maybe I have to just fork the GraphQL library we're using. |
Fixed it better with 80192a5, up to 3rd party plugins to follow suit. |
Sorry to add noise to this issue @andris-sevcenko, but is there a reason this doesn't work? My field returns a fixed array of scalar values so I don't think I need to get a resolver involved: public function getContentGqlType()
{
$typeName = $this->handle.'_SnipcartField';
$productDetailsType = GqlEntityRegistry::getEntity($typeName)
?: GqlEntityRegistry::createEntity($typeName, new ObjectType([
'name' => $typeName,
'fields' => [
'sku' => Type::string(),
'price' => Type::float(),
'shippable' => Type::boolean(),
'taxable' => Type::boolean(),
'weight' => Type::float(),
'weightUnit' => Type::string(),
'length' => Type::float(),
'width' => Type::float(),
'height' => Type::float(),
'inventory' => Type::int(),
'dimensionsUnit' => Type::string(),
],
]));
return $productDetailsType;
} The field is defined and present in the schema; it autocompletes in GraphQL tools and everything. The type is registered with
If I add a |
Still not correct though, apparently: craftcms/cms#5067 (comment)
@mattstein because you also have to register the loader that will load this type: TypeLoader::registerType($typeName, function () use ($productDetailsType) { return $productDetailsType ;}); Hoping to address this in a commit today by registering the loader behind the scenes when you're creating the type. |
So close. Thanks @andris-sevcenko! |
Description
When directly querying Craft's GraphQL endpoint, attempting to query plugin-added schemas results in an error:
This can be observed in Super Table and Neo. I'll also test ImageOptimize and Retour and update this issue.
You can get around this by doing either of two things:
1. Use any reference to
__schema
in the body of the query.So...
...would fail while...
...would return the full schema as expected. Or,
2. Patch the GraphQL controller to skip the check for
__schema
:The second method is the only way to avoid further errors working with Gatsby or Gridsome, where it's not always possible to jam
__schema
into its queries.Steps to reproduce
__schema { types { name } }
in the query and try again.$schemaDef = $gqlService->getSchemaDef($schema, true);
.Additional info
The text was updated successfully, but these errors were encountered: