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

GraphQL error: String cannot represent value #74

Closed
joshuabaker opened this issue Apr 20, 2021 · 18 comments · Fixed by #75
Closed

GraphQL error: String cannot represent value #74

joshuabaker opened this issue Apr 20, 2021 · 18 comments · Fixed by #75

Comments

@joshuabaker
Copy link
Contributor

joshuabaker commented Apr 20, 2021

After updating, I’m consistently getting an error with any embed: “String cannot represent value”

{
  "message": "String cannot represent value: {\"url\":\"https:\\/\\/www.youtube.com\\/watch?v=z9Ug-3qhrwY\",\"oembed\":null}",
  "extensions": {
    "category": "graphql"
  }
}

Using Craft 3.6.12.

@reganlawton Do you have any idea what might be causing that?

@reganlawton
Copy link
Member

I'll have to troubleshoot this in the morning but that's very weird did you tell and empty the field and renter that field?

@joshuabaker
Copy link
Contributor Author

Thank you! 🙏🏻

I’ve tried creating a new block too with the same result. I’ll share any further context if I find anything.

@denisyilmaz
Copy link

denisyilmaz commented May 21, 2021

I have the same issue. I tried reentering the videos to a new block (inside NEO) and it then worked again for one site, but when switching to the other site the error appears again.

2021-05-21 08:16:14 [-][-][-][error][GraphQL\Error\Error] String cannot represent value: {"url":"https:\/\/vimeo.com\/546404759","oembed":null}
2021-05-21 08:16:14 [-][-][-][info][application] $_GET = [
    'p' => 'api'
]

I tried disabling/enabling Cache and GDPR options but without any luck.

@joshuabaker
Copy link
Contributor Author

So the GraphQL error here suggests that the JSON isn’t getting decoded somehow. I’ve witnessed JSON data getting doubly encoded before in Craft and wonder if that might be what’s happening here (i.e. after decoding the JSON, it’s actually still a string).

@denisyilmaz Do you still have an example where this doesn’t work? If so, you might try putting Json::decodeIfJson call after this line locally to see if that fixes it.

@denisyilmaz
Copy link

yes, for example this project has this error currently live: https://www.basics.berlin/de/styling/artists/julius-forgo/projekt/bmw-vision-i-next

when switchtig to english (top right) the same query with different lang param is send to the server (but there the translated oembed field returns the error above).

The error is reproducable:

  1. add a new neo block with the oembed field in it
  2. add a vimeo link
  3. save entry
  4. open entry in one language: oembed field works
  5. open same entry in other language: oembed field fails

The language where the field is first saved in and the language first called in the frontend must not be the same to get it to work the same time. It seems a GraphQL Cache is filled with the value which then is decoded a second time when the other language is called. can that be?

@denisyilmaz
Copy link

@joshuabaker i modified the line as you suggested but it still did not work:

if (is_string($value) && $decValue = Json::decodeIfJson($value, true)) {
    if (isset($decValue['url'])) {
        return new OembedModel($decValue['url']);
    }
}

@denisyilmaz
Copy link

denisyilmaz commented May 27, 2021

acutally, i tried differend options. this one worked once for both languages, but only if applied after the entry was saved and before the query was called the first time:

if (is_string($value) && $decValue = Json::decodeIfJson($value, true)) {
    if (isset($decValue['url'])) {
        if(Json::isJsonObject($decValue['url'])) {
            $decValue = Json::decodeIfJson($decValue['url']);
        }
        return new OembedModel($decValue['url']);
    }
}

Otherswise the backend fails on save with error, which is the expected behavior:

Argument 1 passed to craft\helpers\Json::isJsonObject() must be of the type string, array given, called in /home/www/vendor/wrav/oembed/src/fields/OembedField.php on line 117

somewhere in this the value of $decValue['url'] seems to get saved back to the database.

because when I test to return only the $decValue (not the url field) i get following error:

[
  {
    "message": "String cannot represent value: {\"url\":{\"url\":\"https:\\/\\/vimeo.com\\/210599507\",\"oembed\":null},\"oembed\":null}",
    "extensions": {
      "category": "graphql"
    }
  }
]

so it seems new OembedModel() is called multiple times at some point, because it seems a string of the actual oembed object gets saved as the url of another oembed object:

{\"url\":{\"url\":\"https:\\/\\/vimeo.com\\/210599507\",\"oembed\":null},\"oembed\":null}

@joshuabaker
Copy link
Contributor Author

@denisyilmaz That’s a good find. I’m seeing the same nested object in the url attribute on another site.

image

@devinpitcher
Copy link

To add some additional data, I am running into this as well.

The error is thrown when using a YouTube URL in this format:
https://youtu.be/9wfbEC_es94

Updating to the format below did not throw the error:
https://youtube.com/watch?v=9wfbEC_es94

@joshuabaker
Copy link
Contributor Author

@devinpitcher That sounds unrelated, to be honest. Are you finding that consistently with short YouTube URLs? Might be worth opening a separate issue.

@devinpitcher
Copy link

@devinpitcher That sounds unrelated, to be honest. Are you finding that consistently with short YouTube URLs? Might be worth opening a separate issue.

Yeah, I added four entries with short URLs, and one with a regular URL, and all the short URLs errored out but the standard URL was fine.

@joshuabaker
Copy link
Contributor Author

@devinpitcher I think this is just a coincidence. That short URL works fine for me using the latest version.

image

@devinpitcher
Copy link

I get the previews, but I get the error when attempting to query via GraphQL.

@andrewhawkes
Copy link

I'm currently returning code on the field in a GraphQL query but it's no longer returning for new Vimeo videos.
Could this be related?

@andrewhawkes
Copy link

I've had a bit of a dip into the DB and seeing how the field data is saved. It looks like something has changed recently which is causing the data to be saved in a different way:

Working

{"url":"https://vimeo.com/492107391","oembed":null}

Not working
{"url":{"url":{"url":"https://vimeo.com/528336142","oembed":null},"oembed":null},"oembed":null}

@reganlawton
Copy link
Member

Yeah there seems to be a legacy issue thats changing it to to repeat itself inside itself. This why have been an issue from Craft 1 or 2 days BUT I think @joshuabaker your PR #75 fixes this?

@reganlawton
Copy link
Member

I'll update this with the looping that @denisyilmaz considered

@reganlawton reganlawton reopened this Jun 15, 2021
@reganlawton
Copy link
Member

reganlawton commented Jun 15, 2021

I tagged v1.3.8 with some testing vectors that I could think up and if you are able to change I'll get it a couple of days till I close this issue.

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

Successfully merging a pull request may close this issue.

5 participants