Comments (8)
Thanks for the quick answer!
"DangerousUserProvidedUnstructuredJSON" inspired me to find a way to convert the old unstructured data into something structured :D
Closing....
from graphql-js.
@orktes could you provide an example of how you are trying to use this with a query? I tried doing something similar but cannot seem to figure out how to format the query.
from graphql-js.
Can you explain what you mean by abstract types in this context? In GraphQL "abstract types" has a concrete definition of Union or Interface types.
If I understand correctly (and please correct me if I don't), the data in question is just unstructured and unpredictable, and so you can't write sane queries against it. Is the fact that you represent the data as JSON is a coincidence, and it could have just as easily been binary data, or anything else?
We have a few rare places in Facebook where data operates this way, and we've exposed it through GraphQL as a String, where we actually JSON encode the data on the way out, rather than embedding it directly. This ensures clients don't accidentally index into the data thinking that it is safe, instead requiring an explicit JSON decode to access the unsafe user provided data.
Otherwise, I don't think what you've done here is all that bad, though I may suggest changing the type from "Anything" to "JSON" or something along that line.
Maybe you could offer how you expected or hoped this sort of thing would work?
from graphql-js.
Sorry using "abstract" in this context was a little bit vague, but you understood me correctly :) The data in our case is always JSON (even distinction between object and array is known) but it is otherwise unstructured.
I went with JSON encoding + GraphQLString at first also but that would have resulted in additional refactoring on the client side views so decided to look for something that keeps the old structure of our data.
GraphQLJSONObject is actual naming I use but decided to use GraphQLAnything for the snippet to broaden the question area so discussion here might help people with more varied needs.
I'm otherwise fine with doing it like this, but wanted to ask if mixing non-scalar values with GraphQLScalarType would result in possible side effects now or in the future?
from graphql-js.
I don't think there are any side-effects to worry about. GraphQL will treat this value as a "scalar" as in a "leaf-value" - it just so happens that the output format is just raw.
I would suggest avoiding using naming like "Anything" because it sounds like something to be used. Even "JSONObject" is maybe too reasonable :). I'd suggest something like "DangerousUserProvidedUnstructuredJSON" :P - maybe that's a little extreme, but any way to clearly explain the difference between your well-typed data and ¯_(ツ)_/¯ data is going to be useful.
from graphql-js.
One last note: as currently written your coerceLiteral
method will only work on simple scalar inputs. If you only need GraphQL to describe the output of these unstructured blobs, then maybe even just put a throw Error()
in there... otherwise you may need to focus a little more attention on the array/object literal input cases.
from graphql-js.
Nice! Best of luck
from graphql-js.
@leebyron
Now in 2021, has anything changed about this discussion?
Is there now some other ways to expose unstructured data? Or a scalar string field that contains json representation is still a best practice?
from graphql-js.
Related Issues (20)
- refactor(src): remove `.js` extension, append it for compiled files
- RangeError: Maximum call stack size exceeded in OverlappingFieldsCanBeMergedRule
- Uncaught SyntaxError: missing name after . operator HOT 1
- FieldResolver performance HOT 1
- Inline fragment from an interface to an interface that extends it is invalid
- Resource exhaustion exploit when parsing queries HOT 7
- In GraphQL how to set WriteOnce functionality in specific property in the collection schema
- Generator generates alias imports not compatible with TypeScript Type-Only Imports and verbatimModuleSyntax HOT 2
- Printing the @oneOf directive HOT 1
- Allow shallow sorting with lexicographicSortSchema HOT 2
- Passing arguments into the resolvers by just using `buildSchema` and `graphql`? HOT 3
- Error after upgrading from 16.6 to 16.8.1 with globalThis.process.env.NODE_ENV HOT 12
- Add: Link to new api docs in the README of this project.
- Introspection result missing interfaces
- Detect subscription successfully started
- Errors thrown when iterating over subscription source event streams (AsyncIterables) should be caught HOT 1
- graphql resolver circular dependency type error (bi-directional relation) HOT 1
- Current main is up to 50% slower than previous major version HOT 10
- Type definition for `DefinitionNode` appears to be wrong HOT 4
- AST: `IntValueNode` and `FloatValueNode` store values as string HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphql-js.