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

Contrib data types cause type error (metatag issue) #609

Closed
pmelab opened this issue May 17, 2018 · 10 comments

Comments

@pmelab
Copy link
Contributor

commented May 17, 2018

If a module (e.g. metatag) introduces a new primitive data type, it is not part of the derived types, but any field using it will reference it. That results in a "Missing type metatag." exception.

@pmelab

This comment has been minimized.

Copy link
Contributor Author

commented May 17, 2018

The current workaround is to create a custom scalar:

<?php

namespace Drupal\custom\Plugin\GraphQL\Scalars;

use Drupal\graphql\Plugin\GraphQL\Scalars\Internal\StringScalar;

/**
 * Metatag module dummy type.
 *
 * Metatag module defines a custom data type that essentially is a string, but
 * not called string. And the GraphQL type system chokes on that.
 *
 * @GraphQLScalar(
 *   id = "metatag",
 *   name = "metatag",
 *   type = "string"
 * )
 */
class MetatagScalar extends StringScalar {

}

@pmelab pmelab changed the title Contrib data types cause type error Contrib data types cause type error (metatag issue) May 17, 2018

@bappa-ww

This comment has been minimized.

Copy link

commented Jun 4, 2018

I am facing wsod issue at url /graphql/explorer after I installed metatag module

Uncaught TypeError: Cannot read property 'types' of undefined
    at i (bundle.min.js?v=8.5.3:1)
    at Object.attach (bundle.min.js?v=8.5.3:1)
    at drupal.js?v=8.5.3:25
    at Array.forEach (<anonymous>)
    at Object.Drupal.attachBehaviors (drupal.js?v=8.5.3:22)
    at drupal.init.js?v=8.5.3:16
    at HTMLDocument.t (ready.min.js?v=1.0.8:4)
@bappa-ww

This comment has been minimized.

Copy link

commented Jun 5, 2018

@pmelab Fixed the issue by adding the custom scalar for the metatag as you mentioned! Thanks!

@weitzman

This comment has been minimized.

Copy link
Contributor

commented Jun 21, 2018

same error here ... shall we ask the metatag module add this plugin to its codebase?

@damienmckenna

This comment has been minimized.

Copy link

commented Jun 21, 2018

Out of interest, does this fix the problem too? https://www.drupal.org/project/metatag/issues/2977545

@damienmckenna

This comment has been minimized.

Copy link

commented Jun 21, 2018

Ah! The patch in 2977545 is pmelab's code above, thank you for that.

@damienmckenna

This comment has been minimized.

Copy link

commented Jun 21, 2018

I've committed @pmelab's change (via @bappa-ww) to the Metatag module, it'll be in the next release. Feel free to reach out directly, or post in the module's issue queue, if you find any other problems or have suggestions. Thank you!

@pmelab

This comment has been minimized.

Copy link
Contributor Author

commented Jul 23, 2018

@damienmckenna thanks for fixing this in metatag!

But I think we need a more generic solution. Primitives are a valid extension point of typed data and we can't force every other module to think about GraphQL types.

Perhaps just auto-add a String-like type for every unknown primitive?

@bappa-ww

This comment has been minimized.

Copy link

commented Jul 23, 2018

@pmelab I agree to add a String type for any unknown primitive by default!

@fubhy

This comment has been minimized.

Copy link
Contributor

commented Sep 13, 2018

Solved in #665

@fubhy fubhy closed this Sep 13, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.