0
votes

I'm using a custom YAML type to process a string read from a Markdown frontmatter. This type generates an array of objects depending on the input, and it's not possible to know the exact shape of the resulting data.

This means, the graphql schema generated at compile time cannot infer the type, and throws an error. Is there a way to disable type annotation for a specific field in a frontmatter?

index.md

---
foo: !customType "[Foo][Bar]"
bar: !customType "[[a][b]][c]"
---

Then, I want to query it like:

query IndexQuery {
    foo // Should give me [Object(Foo), Object(Bar)]
    bar // Should give me [[Object(a), Object(b)], Object(c)]
}

I read this, but this seems to require me to create a new type based on a whole document which doesn't really scale.

1

1 Answers

1
votes

GraphQL does not support dynamic schemas, so the field would need to match across all instances. You could generate unique types and a union for your GraphQL queries, but it seems superfluous. Instead you may want to treat the data as a string and use JSON.parse() in your component to convert it to a usable state.