-
Hi everyone, for a hobby project I'm trying graphql-mesh with json-schema to turn a rest API into a GraphQL endpoint. Followed the documentation, but have some trouble. I want to move up the array response of the rest API. SituationI want to turn this query MyQuery {
sleep { # <-- Get rid of this level
sleep {
start
end
score
}
}
} schema {
query: Query
}
type Query {
sleep: Sleep_History
}
type Sleep_History { //
sleep: [Sleep_Entry] // <-- Get rid of this level
} //
type Sleep_Entry {
start: DateTime
end: DateTime
score: Int
} into this (directly returning the array of entries under the query): query MyQuery {
sleep {
start
end
score
}
} schema {
query: Query
}
type Query {
sleep: [Sleep_Entry]
}
type Sleep_Entry {
start: DateTime
end: DateTime
score: Int
} ProblemI followed the example in the documentation, it builds and looks as I want it. But when I run the query, it just returns ExampleSay my {
"sleep": [
{
"start": "2010-01-01T01:00:00+01:00",
"end": "2011-01-01T01:00:00+01:00",
"score": 123
},
{
"start": "2012-01-01T01:00:00+01:00",
"end": "2013-01-01T01:00:00+01:00",
"score": 123
},
// (...)
]
} The {
"type": "object",
"title": "Sleep History",
"properties": {
"sleep": {
"title": "History",
"type": "array",
"items": [
{
"type": "object",
"title": "Sleep Entry",
"properties": {
"start": {
"type": "string",
"format": "date-time"
},
"end": {
"type": "string",
"format": "date-time"
},
"score": {
"type": "number"
}
}
}
]
}
}
} The sources:
- name: SleepAPI
handler:
jsonSchema:
baseUrl: https://api.polarbears.com/v1/
operations:
- type: Query
field: sleep
path: /sleep
method: GET
responseSchema: .json-schemas/polarbears/sleep.json
transforms: #
- replace-field: # Analog from the
replacements: # Documentation
- from: #
type: Query # <- Schema Query
field: sleep #
to: #
type: Sleep_History # <- Replace with
field: sleep # Array of Entries
scope: hoistValue # Thank you for any guidance.
Versions
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Hi @D1no , Are you able to share a Codepen or repository with a reproduction of this issue, so we can investigate? In the meantime, can you copy/paste your generated GraphQL schemas without the transform and with the transform? |
Beta Was this translation helpful? Give feedback.
-
Edit: I posted this as an Issue now #3533 Thank you for the quick reply @santino. Sure, here you go: As Codesandbox: The Reproduction Repository:
Schema: Before Transformschema {
query: Query
}
type Query {
sleep: Sleep_History
}
type Sleep_History {
sleep: [Sleep_Entry]
}
type Sleep_Entry {
start: DateTime
end: DateTime
score: Float
}
"A date-time string at UTC, such as 2007-12-03T10:15:30Z, compliant with the `date-time` format outlined in section 5.6 of the RFC 3339 profile of the ISO 8601 standard for representation of dates and times using the Gregorian calendar."
scalar DateTime Schema: After Transformschema {
query: Query
}
type Query {
sleep: [Sleep_Entry]
}
type Sleep_Entry {
start: DateTime
end: DateTime
score: Float
}
"A date-time string at UTC, such as 2007-12-03T10:15:30Z, compliant with the `date-time` format outlined in section 5.6 of the RFC 3339 profile of the ISO 8601 standard for representation of dates and times using the Gregorian calendar."
scalar DateTime After transform, schema is as expected but the return is |
Beta Was this translation helpful? Give feedback.
-
Following up in #3533 I think you can mark this as answered since this has been done on the issue thread. |
Beta Was this translation helpful? Give feedback.
Following up in #3533
I think you can mark this as answered since this has been done on the issue thread.