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

convert remoteDoc.document if string #851

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

caspervk
Copy link

@caspervk caspervk commented Dec 6, 2024

The specific remote document url I am having issues with is https://digstsgql.magentahosted.dk/graphql?query=query+MyQuery%7Borganisations%7BregisteredBusinessCode%7D%7D:

curl -D- 'https://digstsgql.magentahosted.dk/graphql?query=query+MyQuery%7Borganisations%7BregisteredBusinessCode%7D%7D'

HTTP/2 200 
alt-svc: h3=":443"; ma=2592000
content-type: application/json
date: Wed, 18 Dec 2024 16:56:31 GMT
link: <https://digstsgql.magentahosted.dk/graphql/contexts/QlpoOTFBWSZTWfpVSmMAAKTdgAgAWAe_cFkAv-_f2jAAwwNEU_VGJptGp6jyRgho2piaGABo0NGEZNBo00BgklNBPRoE0AGgAB6myFUCHrtHK0o23oU-xgyMzIwvywpFuhoJhDWoo1iLuKqGr3Jcy26d9EtlPty3HNgtDweCDRooAUhYwfYU55wJXADaQdaqXtxAr0JM4DmhalkGCxmMpgbm3mFqCOT8WmRApIK1YvHjNSaBoD56arVepVI5pmD0apw3YIova_3aXXsV1sT0WSh8bKVjywdh-JKlKNFUqVpKBycq1FRIHfBrqghH6KKzfxdyRThQkPpVSmM=.jsonld>;rel="http://www.w3.org/ns/json-ld#context";type="application/ld+json"
server: Caddy
server: uvicorn
content-length: 861

{"data": {"organisations": [{"registeredBusinessCode": null}, {"registeredBusinessCode": "45152278"}, {"registeredBusinessCode": "45152286"}, {"registeredBusinessCode": "45152294"}, {"registeredBusinessCode": "45152308"}, {"registeredBusinessCode": "45152324"}, {"registeredBusinessCode": "45152332"}, {"registeredBusinessCode": "45152340"}, {"registeredBusinessCode": "45152367"}, {"registeredBusinessCode": "45152375"}, {"registeredBusinessCode": "37284114"}, {"registeredBusinessCode": "29189781"}]}, "extensions": {"@context": {"data": {"@id": "https://data.gov.dk/dataresponse/fe41b981-629d-46b5-a4ce-58c33fd1559c", "@context": {"organisations": {"@id": "http://www.w3.org/ns/org#FormalOrganization", "@container": "@set", "@context": {"registeredBusinessCode": {"@id": "https://data.gov.dk/model/core/organisation/extension/registeredBusinessCode"}}}}}}}}

Following the Link header:

curl -D- 'https://digstsgql.magentahosted.dk/graphql/contexts/QlpoOTFBWSZTWfpVSmMAAKTdgAgAWAe_cFkAv-_f2jAAwwNEU_VGJptGp6jyRgho2piaGABo0NGEZNBo00BgklNBPRoE0AGgAB6myFUCHrtHK0o23oU-xgyMzIwvywpFuhoJhDWoo1iLuKqGr3Jcy26d9EtlPty3HNgtDweCDRooAUhYwfYU55wJXADaQdaqXtxAr0JM4DmhalkGCxmMpgbm3mFq
COT8WmRApIK1YvHjNSaBoD56arVepVI5pmD0apw3YIova_3aXXsV1sT0WSh8bKVjywdh-JKlKNFUqVpKBycq1FRIHfBrqghH6KKzfxdyRThQkPpVSmM=.jsonld'
HTTP/2 200 
alt-svc: h3=":443"; ma=2592000
content-type: application/ld+json
date: Wed, 18 Dec 2024 16:59:45 GMT
server: Caddy
server: uvicorn
content-length: 329

{"@context":{"data":{"@id":"https://data.gov.dk/dataresponse/fe41b981-629d-46b5-a4ce-58c33fd1559c","@context":{"organisations":{"@id":"http://www.w3.org/ns/org#FormalOrganization","@container":"@set","@context":{"registeredBusinessCode":{"@id":"https://data.gov.dk/model/core/organisation/extension/registeredBusinessCode"}}}}}}}

The playground does not seem to treat the first response as JSON, and so it is unable to inject the Link header into the document ("@context": "<url>"). It never even attempts to retrieve the JSON-LD document from the Link header.

The first commit adds an error to the console in this case (this took a while to realise), while the second commit converts the string to a proper object, fixing the issue. I do not understand why this document is not already of the correct type. Perhaps it has to do with using the legacy XMLHttpRequest API rather than fetch, but I am not sure.

main @ ffd3d11:

image

https://json-ld.org/playground/#startTab=tab-expanded&json-ld=https%3A%2F%2Fdigstsgql.magentahosted.dk%2Fgraphql%3Fquery%3Dquery%2BMyQuery%257Borganisations%257BregisteredBusinessCode%257D%257D

After PR:

image

https://digstsgql.magentahosted.dk/json-ld.org/playground/#startTab=tab-expanded&json-ld=https%3A%2F%2Fdigstsgql.magentahosted.dk%2Fgraphql%3Fquery%3Dquery%2BMyQuery%257Borganisations%257BregisteredBusinessCode%257D%257D

@caspervk
Copy link
Author

Updated PR description. Apologises for not properly describing the issue and attempted solution sooner.

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

Successfully merging this pull request may close these issues.

2 participants