https://www.prisma.io/ logo
Join Slack
Powered by
# prisma-whats-new
  • n

    nilan

    02/01/2017, 4:09 PM
    because sometimes you really need the id 🙂
  • a

    ambethia

    02/01/2017, 4:09 PM
    will I need to do that if I want to create a new family and say that the current user owns it?
  • n

    nilan

    02/01/2017, 4:09 PM
    exactly!
  • n

    nilan

    02/01/2017, 4:09 PM
    then you can do
    Copy code
    mutation {
      createFamily(userId: "id", title: "My Family") {
        id
      }
    }
  • a

    ambethia

    02/01/2017, 4:10 PM
    I assume thats possible to enforce with a permission query, make sure that the user id the client passes is the same as $userId?
  • n

    nilan

    02/01/2017, 4:10 PM
    it's possible with a new exciting feature that we call permission queries
  • n

    nilan

    02/01/2017, 4:10 PM
    that's available through our beta program and we're rolling it out soon
  • a

    ambethia

    02/01/2017, 4:10 PM
    Awesome, Johannes invited me to that beta the other night 😉
  • n

    nilan

    02/01/2017, 4:11 PM
    👍
  • a

    ambethia

    02/01/2017, 4:11 PM
    I think I spelled that right, sorry if not
  • a

    ambethia

    02/01/2017, 4:11 PM
    @schickling
  • n

    nilan

    02/01/2017, 4:11 PM
    😄 yea, all good
  • a

    ambethia

    02/01/2017, 4:11 PM
    🚀
  • a

    ambethia

    02/01/2017, 6:27 PM
    <!here|@here> I have these query/mutations:
    Copy code
    const FamiliesQuery = gql`query {
      user {
        id
        ownedFamilies(orderBy: name_ASC) {
          id
          name
        }
      }
    }`
    
    const CreateFamilyMutation = gql`
      mutation ($name: String!, $ownerId: ID) {
        createFamily(name: $name, ownerId: $ownerId) {
          id
          name
        }
      }
    `
    
    export default (
      graphql(CreateFamilyMutation)(graphql(FamiliesQuery)(FamilyList))
    )
  • a

    ambethia

    02/01/2017, 6:27 PM
    and in my client:
    new ApolloClient({ dataIdFromObject: o => o.id, networkInterface })
  • a

    ambethia

    02/01/2017, 6:28 PM
    but when I add a family, I need to reload to see it
  • a

    ambethia

    02/01/2017, 6:28 PM
    is it because
    ownedFamilies
    and
    createFamily
    mutation results are cached differently?
  • n

    nilan

    02/01/2017, 6:28 PM
    Hey @ambethia, this is caused by the fact that the id of the newly created family is not yet known to Apollo
  • n

    nilan

    02/01/2017, 6:29 PM
    no, this is not the problem. Using
    updateFamily
    doesn't show that behaviour, it updates without a reload
  • n

    nilan

    02/01/2017, 6:30 PM
    There are different options to handle this * if you don't have a lot of families, you can call
    this.props.data.refetch()
    in the
    then
    of the mutation. This refetches the whole query though, which is not performant for a lot of data... * the efficient way to do it is to define
    updateQueries
    on the
    createFamily
    mutation.
  • n

    nilan

    02/01/2017, 6:30 PM
    Some resources for the second approach: * https://www.learnapollo.com/excursions/excursion-02/ * http://dev.apollodata.com/react/cache-updates.html#updateQueries
  • a

    ambethia

    02/01/2017, 6:31 PM
    Ah ok, thanks!
  • a

    ambethia

    02/01/2017, 6:31 PM
    I was looking at https://www.learnapollo.com/excursions/excursion-02/ and I realized just now I needed to keep reading:
    While specifying
    dataIdFromObject
    like that helps when working with queries and updating nodes, we have to do a bit more to make caching consistent in combination with creating or deleting nodes.
  • n

    nilan

    02/01/2017, 6:31 PM
    Haha, funny enough
  • a

    ambethia

    02/01/2017, 6:32 PM
    I appreciate it! I love feeling like a noob again.
  • a

    ambethia

    02/01/2017, 6:32 PM
    (not sarcastic, it's fun!)
  • n

    nilan

    02/01/2017, 6:32 PM
    🎉
  • n

    nilan

    02/01/2017, 6:33 PM
    depending on the Apollo client version you're using you might also run into this problem: https://github.com/apollographql/apollo-client/issues/1129
  • a

    ambethia

    02/01/2017, 6:34 PM
    Copy code
    cat yarn.lock | grep apollo-client
    apollo-client@^0.8.1:
  • n

    nilan

    02/01/2017, 6:35 PM
    haven't had the change to check if that works. From what I've seen, this is currently unresolved...
1...949596...637Latest