arackaf / mongo-graphql-starter

Creates a fully functioning, performant, extensible GraphQL endpoint from a Mongo DB. Supports middleware, Mongo 4 transactions.
MIT License
423 stars 29 forks source link

JSON Type #21

Closed erikras closed 6 years ago

erikras commented 6 years ago

How hard would it be to add something like graphql-type-json to this lib?

arackaf commented 6 years ago

Probably easy! Lemme take a look in a few days.

erikras commented 6 years ago

In case it isn't obvious, I've got a Mongo field where I want to plop a big old JSON object and not have to worry about specifying its precise shape in the GraphQL schema. That's the sort of thing Mongo excels at.

arackaf commented 6 years ago

Yep yep! Should be possible.

erikras commented 6 years ago

I looked into implementing this myself and pretty quickly got overwhelmed.

Not to Bill-Lumbergh you too hard, but it would be really awesome if this could get done early this week. πŸ˜„ πŸ™

arackaf commented 6 years ago

Yeah the code could be better πŸ˜‚

It’s actually an easy implementation (once you know where everything is). I’m flying today - was gonna see about implementing this tomorrow

erikras commented 6 years ago

Yeah, I just saw your tweet about airports and felt bad for pressuring you. 😳

arackaf commented 6 years ago

@erikras This should be done, and deployed to npm. It's not documented (yet) but to see how to use it, check out the PR, in particular files

test/testProject1/projectSetup.js to see how to add a json property,

and

test/testProject1/jsonType.test.js to see how to use it.

https://github.com/arackaf/mongo-graphql-starter/pull/22/files

But the gist is, you can now send arbitrary js content over for a json field, and it'll be saved as is. You can't filter based on the json structure (obviously, it's an arbitrary format, which is the whole point) but you can pull the field down, and update the existing value.

erikras commented 6 years ago

This looks good.

I wanna filter on the truthiness of the field, though. i.e. "Does it have a value?" Is that possible?

I guess the way that's normally done is with a jsonContent_ne: null?

arackaf commented 6 years ago

Hm - yeah that should be possible

arackaf commented 6 years ago

@erikras lemme know if you need anything else :)