Apollo-client: Fragments with only @client local state data throw exception

Created on 2 Mar 2019  路  5Comments  路  Source: apollographql/apollo-client

Intended outcome:
Be able to query local state with a fragment that only includes @client data:

query MyQuery {
  ...RootQueryFragment
}

fragment RootQueryFragment on Query {
  localStateMessage @client
}

Actual outcome:

Throws an exception:

  TypeError: Cannot read property 'selectionSet' of undefined
      at isEmpty (bundle.esm.js:529)
      at bundle.esm.js:530
      at Array.every (<anonymous>)
      at isEmpty (bundle.esm.js:529)
      at nullIfDocIsEmpty (bundle.esm.js:535)
      at removeDirectivesFromDocument (bundle.esm.js:551)
      at removeConnectionDirectiveFromDocument (bundle.esm.js:666)
      at ApolloLink.request (bundle.esm.js:2601)
      //...

It works when no fragment is used:

  query MyQuery {
    localStateMessage @client
  }

It also works when the fragment includes non-local data (i.e. without @client):

  query MyQuery {
    ...RootQueryFragment
  }

  fragment RootQueryFragment on Query {
    localStateMessage @client
    people {
      id
      name
    }
  }

How to reproduce the issue:

See 4529-local-state-fragments branch of my react-apollo-error-template fork.

Versions

System:
  OS: Linux 4.20 Arch Linux
Binaries:
  Node: 11.9.0 - /usr/bin/node
  Yarn: 1.13.0 - /usr/bin/yarn
  npm: 6.7.0 - /usr/bin/npm
Browsers:
  Firefox: 65.0
  // This wasn't detected but I was actually running the example in Chromium
  Chromium: 72.0.3626.81
npmPackages:
  apollo-cache-inmemory: 1.5.1 => 1.5.1 
  apollo-client: 2.5.1 => 2.5.1 
  apollo-link: 1.2.8 => 1.2.8 
  react-apollo: 2.1.4 => 2.1.4 

Most helpful comment

@hwillson any updates on this?

All 5 comments

@hwillson any updates on this?

Also running into this issue. Curious if anyone has found a solution.

any updates?

This also happened for me when the fragment name was wrong. Worth double-checking.

It's not a very helpful error message at all, mind you.

Running into a similar problem

export const TEST_DATA_QUERY = gql`
  query TestPageDataQuery {
    me {
      id
    }
    ...ProfileData
  }
  ${profileStateFragment}
`

export const profileStateFragment = gql`
  fragment ProfileData on Query {
    profileClickCount @client
  }
`

Will cause the client to send the fragment to the server and the server will return an error

Was this page helpful?
0 / 5 - 0 ratings

Related issues

skeithtan picture skeithtan  路  3Comments

dispix picture dispix  路  3Comments

stubailo picture stubailo  路  3Comments

treecy picture treecy  路  3Comments

stubailo picture stubailo  路  3Comments