Programatically add single field to Schema

Hi! I’m trying to enable a workflow that allows a type to accept arbitrary fields.

Basically my type is an object with unknowable fields, that I want to resolve as strings. I’ll also want to query on these fields. My understanding is that for this to be possible at all I need to update the schema to define the field as soon as I know what the field is.

So far, I’ve gotten to the point where I accept an object, write a new .gql schema that defines each field in that object, the query for adding the index for each field, and imports that via merge to the import endpoint. It works great! Fantastic!

BUT apparently this is how we also delete fields. So each schema update is blowing away the type def that has my other fields. Not ideal, not great!

So; how do I merge a single new field or a single new query into my GraphQL schema without deleting any extant fields?

You need to merge the object with the existing schema definition. If you treat the object as the new schema definition without merging, then you would lose fields.

To do the merge, you need to keep track of the schema that has already been uploaded.

If you need arbitrary data returned, one possibility would be to use a graphql/fql hybrid approach. Graphql could return ids. Then you could use a native fauna client to directly grab the data with those ids.

Tracking the schema sounds like a pain - too finicky with a potential for data loss.

I like the GraphQL/FQL approach - I realized that “using GraphQL” is not necessarily a hard requirement for this use case so creating indexes and consuming data with FQL is totally viable.