json-ld api doesn't return fields that are defined as interfaces
Closed this issue · 1 comments
when using the document api, only fields that are scalars or links to concrete types are returned. For example, a query
query {
MusicComposition {
identifier
composer {
... on Person {
name
}
}
workExample {
... on MediaObject {
identifier
}
}
}
}
which returns
{
"data": {
"MusicComposition": [
{
"identifier": "479ee0b6-9c9d-4e0c-b8bd-9350b2825dc9",
"composer": [
{
"name": "Jacob Handl"
}
],
"workExample": [
{
"identifier": "4fe5a535-385f-4328-9f6c-60bc557b4f16"
},
{
"identifier": "02db0711-a356-4436-bee6-ef0bd7a8760e"
},
{
"identifier": "0df44126-89cd-4b33-8605-b4ae03eb84e6"
}
]
}
]
}
}
however, the json-ld response only includes:
{
"dc:source": "https://cpdl.org/wiki/index.php/Ab_Oriente_venerunt_Magi_(Jacob_Handl)",
"associatedArticle": [],
"dc:type": null,
"rdf:type": null,
"dc:relation": null,
"disambiguatingDescription": null,
"character": [],
"dc:modified": "2021-04-10T20:46:28.597000000Z",
"text": null,
"height": null,
"regionsAllowed": [],
"dc:identifier": "479ee0b6-9c9d-4e0c-b8bd-9350b2825dc9",
"identifier": "479ee0b6-9c9d-4e0c-b8bd-9350b2825dc9",
"image": null,
"schema_publisher": [],
"workExampleMediaObject": [ {
"@id": "http://localhost:4000/4fe5a535-385f-4328-9f6c-60bc557b4f16"
}]
}
It includes things like source
which is just a String, and it also includes workExampleMediaObject
which is our special field with the same relation name as workExample
but with a type of MediaObject
rather than ThingInterface.
The fields for workExample and composer don't appear in the returned json.
The issue seems to be that SchemaHelper.findInterfaceImplementingTypes
ce-api/src/helpers/QueryHelper.js
Lines 96 to 97 in c95fc49
is returning null when trying to find
schema.getImplementations
of an interface name.It looks like the interface a schema in graphql-tools changed since we upgraded it. This patch appears to work:
diff --git a/src/helpers/SchemaHelper.js b/src/helpers/SchemaHelper.js
index 2cfb675..8ae1638 100644
--- a/src/helpers/SchemaHelper.js
+++ b/src/helpers/SchemaHelper.js
@@ -31,11 +31,11 @@ class SchemaHelper {
*/
findInterfaceImplementingTypes (interfaceName) {
const implementations = this.findInterface(interfaceName)
- if (!Array.isArray(implementations) || !implementations.length) {
+ if (!implementations.objects || !Array.isArray(implementations.objects) || !implementations.objects.length) {
return null
}
- return implementations.map(implementation => { return implementation.toString() })
+ return implementations.objects.map(implementation => { return implementation.toString() })
}
/**
@@ -43,7 +43,7 @@ class SchemaHelper {
* @returns {*|Array<GraphQLObjectType>}
*/
findInterface (interfaceName) {
- return this.schema.getImplementations(interfaceName)
+ return this.schema.getImplementations({name:interfaceName})
}
/**