Missing selection set for object GraphQL+Apollo error

apollo cache not working
apollo graphql
missing selection set on property
apollo client addtypename
missing field __typename in
apollo local state
apollo store graphql
apollo-link-state

I have a set of mutations that trigger the local state of certain types of popups. They're generally set up like this:

  openDialog: (_, variables, { cache }) => {
    const data = {
      popups: {
        ...popups,
        dialog: {
          id: 'dialog',
          __typename: 'Dialog',
          type: variables.type
        }
      }
    };

    cache.writeData({
      data: data
    });
    return null;
  }

And the defaults I pass in look like:

const defaults = {
  popups: {
    __typename: TYPENAMES.POPUPS,
    id,
    message: null,
    modal: null,
    menu: null,
    dialog: null
  }
};

The way they're used in my React code is with a Mutation wrapper component, like so:

const OPEN_ALERT_FORM = gql`
  mutation AlertOpenDialog($type: String!) {
    openDialog(type: $type) @client
  }
`;

class Alert extends Component {
  render() {
    return (
      <Mutation mutation={OPEN_ALERT_FORM} variables={{ type: ALERT_FORM }}>
        {openDialog => {
          return (
            <Button
              classes="alert-button"
              onClick={openDialog}
              label="Trigger Alert"
            />
          );
        }}
      </Mutation>
    );
  }
}

For my various popups (I have 3 or 4 different ones, like menu and modal), the mutations to open and close them all look the same, just different typenames and content etc. But, for Dialogs, I get this error when I click on them:

Network error: Missing selection set for object of type Dialog returned for query field dialog

...and then the triggering component disappears from the page. Plus, once that happens, all other popup types disappear when you try clicking on them, and either re-throw that error, or say:

Uncaught Error: A cross-origin error was thrown. React doesn't have access to the actual error object in development.

I've tried re-writing dialogs to match up with other popup types, and re-writing the components as well, but I'm still getting this error. It does appear to be dialog+Apollo specific. What could be the root of this issue? It can't be a backend thing, because this is only dealing with local Apollo. I haven't seen this error before and I'm not sure where to go from here.

Had the same problem error message. Seems like this is the only question in stackoverflow so far with this same error message in the question.

I will just note down my side of things

In my case, I have a query that is not querying the fields of the object. Anagolous to this case, the query that i have looks like this

{
  popups @client {
    id
    dialog
  }
}

It should be

{
  popups @client {
    id
    dialog {
      id
    }
  }
}

Missing selection set error · Issue #5079 · apollographql/apollo , uncaught Invariant Violation: Missing selection set for object of type Parameter returned for query field parameters. but my query is correct! It is important to handle these errors and when possible, report these errors back to your users for information. Using GraphQL brings a new set of possible errors from the actual GraphQL response itself. With that in mind, here are a few different types of errors: GraphQL Errors: errors in the GraphQL results that can appear alongside

Answer to the actual problem seems lay in the query. Initially Apollo client was not validating types for @client queries/mutations so your mutation could look like you wrote it in the question:

mutation AlertOpenDialog($type: String!) {
  openDialog(type: $type) @client
}

the correct way of writing above is to specify (select) all the simple type (scalar) fields you wanna get in a response. So in regard to the @Vic answer the mutation should look more like:

mutation AlertOpenDialog($type: String!) {
  openDialog(type: $type) @client {
    dialog {
      id
    }
  }
}

apollographql/apollo-client, GraphQL schema has scalar JSON. and, It contains object and array. Invariant Violation: Missing selection set for object of type undefined  Writing data to a specific entity object should not require the additional boilerplate of creating a named fragment with a type condition. All the cache really cares about is the top-level selection set of the query or fragment used to read or write data, and from that perspective queries are an almost perfect substitute for fragments, in almost all cases.

The fix for this turned out to work by treating the dialog field as a string instead of an object. Changing the function to this did the trick and made the errors go away:

  openDialog: (_, variables, { cache }) => {
    const data = {
      popups: {
        ...popups,
        dialog: variables.type
      }
    };

    cache.writeData({
      data: data
    });
    return null;
  }

Missing selection set for object GraphQL+Apollo error, Missing selection set for object GraphQL+Apollo error. likeanswer 2019-04-28. I have a set of mutations that trigger the local state of certain types of popups. Gonna throw in another vote for removing this string, it results in GraphQL error: [Object object] if you have errors with multiple fields. This is broken, bizarre, unnecessary functionality. This is broken, bizarre, unnecessary functionality.

Missing selection set for object GraphQL+Apollo error, Missing selection set for object GraphQL+Apollo error. Multi tool use. up vote 3 down vote favorite. 2. I have a set of mutations that trigger the  @sorenbs this is currently blocked on the store refactor which we're working on at the moment. Currently the plan for the new API is to handle errors the same way as we handle data, and write them into the store as well if they have a path (which means you might retrieve cached errors from the store).

Missing selection set for object GraphQL+Apollo error, Missing selection set for object GraphQL+Apollo error. Multi tool use. up vote 4 down vote favorite. 3. I have a set of mutations that trigger the  I think that @marcospgp and my complaint is that, because the Apollo-Server-Monorepo (root project) and the Apollo-Server package (the one the documentation actually points you to) only list graphql in its devDependencies, it can appear that things are working perfectly locally in development but then cause confusion when you get to production.

Configuring the cache - Client (React), Create an InMemoryCache object and provide it to the ApolloClient constructor like so: the __typename field to every query selection set it sends to the server. Intended outcome: Child component has data from both remote and local state. Actual outcome: Child component gets an empty object. How to reproduce the issue: Our initial query uses the apolloClient.query method as oppose to the <Query /

Comments
  • What does the defaults object you pass to withClientState look like?
  • @DanielRearden just updated question with the defaults!
  • Hmm. It looks like that error gets thrown whenever the cache has some object (as opposed to just a scalar value) and you try to read that object from the cache without specifying a selection set (i.e. which fields on the type). You can take a look at the test here. Do you have a query that requests the dialog field on popups without specifying the fields on dialog?
  • i.e. something like query { popups { dialog } } ?
  • @DanielRearden I'll check that out, thanks! I do have a query that checks that, and it appears to be working correctly.
  • well it does not solve the original question but rather changing data model to avoid the error. You're lucky being free to alter the model ;)