GithubHelp home page GithubHelp logo

Comments (9)

asokani avatar asokani commented on May 8, 2024 6

Any news on this? I also feel a need for something like

query GetTodo($id: ID!) {
  todo(id: $id) {
    id
    title
    completed
  }
}

But I don't really know how to do it. Is there any complex example available for some complex local state with queries with parameters. I only saw local-link-state mutations with parameteres, not queries...

from apollo-link-state.

tkambler avatar tkambler commented on May 8, 2024 4

For something so basic, information on how to do this is surprisingly hard to come by. I believe this is what you're looking for:

/**
 * Apollo link state resolvers
 */
const resolvers = {
    Query: {
        getTodo: (parent, { id }, { cache, getCacheKey }) => {

			return cache.readFragment({
                id: getCacheKey({ __typename: 'Todo', id: id }),
                fragment: gql`
                    fragment myTodo on todos {
                        id
                        label
                        description
                        complete
                    }
                `,
            });

        }
    },
    Mutation: {}
};

from apollo-link-state.

lifeiscontent avatar lifeiscontent commented on May 8, 2024

@peggyrayzis @stubailo @jbaxleyiii I wish I could help you guys write docs. Is there a way I can directly interact with the apollo team in order to help write docs on Apollo?

from apollo-link-state.

stubailo avatar stubailo commented on May 8, 2024

Very surprising that a cache redirect didn't work - that's what I would have suggested! I don't work at Apollo as of 3 months ago, but I can help you get docs PRs merged in!

from apollo-link-state.

jsslai avatar jsslai commented on May 8, 2024

Does this work if you try 2.4 version of ApolloClient? Also what v4() returns for id and what if you try this with static id?

from apollo-link-state.

lifeiscontent avatar lifeiscontent commented on May 8, 2024

@jsslai it's just a uuid v4. from the uuid npm package.

in theory this should "just work" with a cache redirect, but... it doesn't maybe due to something not being setup in apollo-link-state "yet" I'm using the alpha release @peggyrayzis talked about at GraphQL Summit.

from apollo-link-state.

lifeiscontent avatar lifeiscontent commented on May 8, 2024

@tkambler thanks for the solution, but it doesn't solve the case where you call getTodo without all the fields in the fragment it should be deferred to the caller I'd assume.

from apollo-link-state.

darrylyoung avatar darrylyoung commented on May 8, 2024

Did you ever get the solution you were looking for, @lifeiscontent?

from apollo-link-state.

lifeiscontent avatar lifeiscontent commented on May 8, 2024

@darrylyoung no unfortunately not

from apollo-link-state.

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.