Skip to content

Instantly share code, notes, and snippets.

@shangxiao
Created February 28, 2017 01:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shangxiao/b37b165ceecc61e1d3ae10cb38733fef to your computer and use it in GitHub Desktop.
Save shangxiao/b37b165ceecc61e1d3ae10cb38733fef to your computer and use it in GitHub Desktop.
Relay Notes
===========
- Define a schema, that is used for _both_ server side endpoint setup & frontend graphql compilation
- node only for now, some graphql ports
- Relay has a strict specification of how a graphql schema is set up: https://facebook.github.io/relay/docs/graphql-relay-specification.html
- tree children are called "plural links" (see _writePluralLink())
Bad points
----------
- Complex, many new concepts
- Proprietary format
- Reminds me of (the bad points about) SOAP, RequestFactory
- Errors are returned as 200
- No tracebacks if a serverside exception occurs (with graphqllib)
- Error reporting in general isn't the greatest: "null parameter: AttributeError: 'AttributeError' object has no attribute 'message'" with graphqllib
- GraphQLError wrappers hide tracebacks
- errors: null, errors: [] both raise errors on the client
- Root query args must be string, otherwise get some weird invariant violation
- finding answers to q's is hard, a fledgling community
- specifying fragments is hard with mutations & composition
Gotchas
-------
- input into a mutation must be relay output
- optimistic responses must have an id
- optional args must be declared, and must be null
- IMPORTANT: Components can only see the data they queried. If you have child objects that have a field used for keys, make sure to include that field in the query fragment
- And don't be cloning relay props neither, they are of a certain type
- Some operations don't diff properly, eg delete from children, so need to fudge parent field (add a space for eg) in order to make the diff work
Django integration possibilities
--------------------------------
- Existing need due for isomorphic react apps
- exec node script, call python from node with node-python npm package
-
Links
-----
- https://facebook.github.io/react/blog/2015/03/19/building-the-facebook-news-feed-with-relay.html
- http://blog.startifact.com/posts/the-emerging-graphql-python-stack.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment