At a glance
Issue description
This seems like the easiest to start with, defaulting to just the JSON handler of course.
This would satisfy at least 4 open feature requests if not many more.
const jsonResponsePlugin = {
label: "JSON",
parser: (dataString) => JSON.parse(dataString),
editorOptions: {
language: 'json'
},
previewComponent: ({ data }) =>
<JSONGraph data={data} />
}
const json5ResponsePlugin = {
label: "JSON5",
parser: (dataString) => JSON5.parse(dataString),
editorOptions: {
language: 'json5'
},
previewComponent: ({ data }) => <JSONGraph data={data} />
}
<GraphiQL
httpResponsePlugins={{
'application/json': jsonResponsePlugin,
'text/json': jsonResponsePlugin,
'application/json5': json5ResponsePlugin,
}}
/>
Advanced Example
We're going to be able to do some amazing stuff with this 😻 .
export const plugin = {
label: "Markdown",
parser: (dataString) => {
const file = greymatter(dataString)
// operationName, errors, etc
return { ...file.data, data: file.content }
},
editorOptions: {
language: 'markdown'
},
// if there's no serializers, there is no data prop in `previewComponent`
previewComponent: ({ dataString, data }) => (
<>
<article>
<h2>{data.title}</h2>
<div>{md.render(dataString)}</div>
</article>
<aside>
Written by: <Avatar author={data.author} />
</aside>
</>
)
}
Subscriptions GUI?
How would this impact the subscriptions GUI? it would be used to define how each iteration is formatted depending on the response content type
Other Response types
So many have been requested ! None of these are spec of course, but the demand to experiment here has been persistent across many use cases
- Yaml
- Protobufs
- Messagepack
- HTML
- HJSON
- ?