Coder Social home page Coder Social logo

Single entry node about crystal HOT 4 CLOSED

graphile avatar graphile commented on May 9, 2024
Single entry node

from crystal.

Comments (4)

calebmer avatar calebmer commented on May 9, 2024

Could you give me a quick example (pseudo code maybe) of how Relay would use this field? Also, would there be a deprecation plan for this? As it may eventually get removed as Relay removes this constraint?

The only reason I hesitate is I want a definitive resource to refer people to if they have questions about the viewer field, maybe a documentation article would be nice? 😊

Otherwise, its super easy to do.

from crystal.

 avatar commented on May 9, 2024

Sure, there's plenty of examples around. https://facebook.github.io/relay/docs/api-reference-relay-container.html gives a simple use case.

In routing (using react-router-relay):

const viewerQueries = {
  viewer: () => Relay.QL`query { viewer }`,
};

const routes = (
  <Route component={App}>
    <Route path="/" component={Home} queries={viewerQueries} />
    <Route path="/users" component={Users} queries={viewerQueries} />
    <Route path="*" component={NotFound} />
  </Route>
);

In a component:

// ...
export default Relay.createContainer(Home, {
  fragments: {
    viewer: () => Relay.QL`
      fragment on User {
        users {
            // ...
            ${UsersTable.getFragment('users')}
          }
        }
      }
    `,
  },
});

This allows you to re-use viewerQueries for each container / top-level component, without having to know what the underlying data structure is beforehand.

As I said, this kind of approach makes perfect sense for view-driven GraphQL consumers like Relay, and I doubt there'll be a deprecation path necessary (even though there is talk about removing that restriction on the issue I posted above).

Now, I appreciate that this approach won't be required by normal GraphQL consumers that aren't necessarily view-driven (though there still is benefits to building up a graph query from a single entry node), so we should be careful not to break existing implementations.

from crystal.

calebmer avatar calebmer commented on May 9, 2024

See #49.

from crystal.

calebmer avatar calebmer commented on May 9, 2024

Released in 1.5.0 🙌

from crystal.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.