Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails to return result when using only fragment spreads in query operation #2720

Closed
jonaskello opened this issue Dec 13, 2017 · 3 comments
Closed

Comments

@jonaskello
Copy link
Contributor

Issue description

I'm trying to run this query against the swapi demo server with apollo-client:

query MyQuery {
  ...TheFilms
  ...ThePeople
}

fragment TheFilms on Root {
  allFilms {
    films {
      id
      title
    }
  }
}

fragment ThePeople on Root {
  allPeople {
    people {
      name
    }
  }
}

Intended outcome:

I expect apollo-client to return the same result as GraphiQL:

{
  "data": {
    "allFilms": {
      "films": [
        {
          "id": "ZmlsbXM6MQ==",
          "title": "A New Hope"
        },
        {
          "id": "ZmlsbXM6Mg==",
          "title": "The Empire Strikes Back"
        },
        ...
      ]
    },
    "allPeople": {
      "people": [
        {
          "name": "Luke Skywalker"
        },
        {
          "name": "C-3PO"
        },
        ...
      ]
    }
  }
}

Actual outcome:

apollo-client returns this:

{ data: {}, loading: false, networkStatus: 7, stale: false }

How to reproduce the issue:

Here is a repo with code that reproduces the issue.

Here is the code to reproduce:

async function main() {
  const ApolloClient = require("apollo-client").ApolloClient;
  const HttpLink = require("apollo-link-http").HttpLink;
  const InMemoryCache = require("apollo-cache-inmemory").InMemoryCache;
  const fetch = require("node-fetch");
  const gql = require("graphql-tag");

  const client = new ApolloClient({
    link: new HttpLink({
      uri: "http://graphql.org/swapi-graphql",
      fetch: fetch
    }),
    cache: new InMemoryCache()
  });

  const query = gql`
    query MyQuery {
      ...TheFilms
      ...ThePeople
    }

    fragment TheFilms on Root {
      allFilms {
        films {
          id
          title
        }
      }
    }

    fragment ThePeople on Root {
      allPeople {
        people {
          name
        }
      }
    }
  `;

  const result = await client.query({ query });
  console.log("result", result);
}

main();

Version

  • apollo-client@2.0.4
@jaydenseric
Copy link
Contributor

jaydenseric commented Dec 14, 2017

Related to #2512?

@jonaskello
Copy link
Contributor Author

jonaskello commented Dec 14, 2017

I found today that this only happens when you have a query operation that only has fragment spreads and nothing else. If I add something else, like a regular field, to the query operations selection set then it works and the spreads are also resolved.

For example this would work:

query MyQuery {
  ...TheFilms
  ...ThePeople
  allPlanets {
    totalCount
  }
}

fragment TheFilms on Root {
  allFilms {
    films {
      id
      title
    }
  }
}

fragment ThePeople on Root {
  allPeople {
    people {
      name
    }
  }
}

@jonaskello jonaskello changed the title Fails to return result when using fragment on root Fails to return result when using only fragment spreads in query operation Dec 14, 2017
@hwillson
Copy link
Member

hwillson commented Jul 3, 2018

This should have been fixed by #3507. Let us know if this is still a problem. Thanks!

@hwillson hwillson closed this as completed Jul 3, 2018
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants