Search code examples
graphqlapolloapollo-server

grapql@16 dropped long-deprecated support for positional arguments, please pass an object instead


    const { ApolloServer, gql } = require('apollo-server');
    
    // A schema is a collection of type definitions (hence "typeDefs")
    // that together define the "shape" of queries that are executed against
    // your data.
    const typeDefs = gql`
      # Comments in GraphQL strings (such as this one) start with the hash (#) symbol.
    
      # This "Book" type defines the queryable fields for every book in our data source.
      type Book {
        title: String
        author: String
      }
    
      # The "Query" type is special: it lists all of the available queries that
      # clients can execute, along with the return type for each. In this
      # case, the "books" query returns an array of zero or more Books (defined above).
      type Query {
        books: [Book]
      }
    `;
const books = [
  {
    title: 'The Awakening',
    author: 'Kate Chopin',
  },
  {
    title: 'City of Glass',
    author: 'Paul Auster',
  },
];

// Resolvers define the technique for fetching the types defined in the
// schema. This resolver retrieves books from the "books" array above.
const resolvers = {
  Query: {
    books: () => books,
  },
};

// The ApolloServer constructor requires two parameters: your schema
// definition and your set of resolvers.
const server = new ApolloServer({ typeDefs, resolvers });

// The `listen` method launches a web server.
server.listen().then(({ url }) => {
  console.log(`🚀  Server ready at ${url}`);
});

So this is the code I copied from official Apollo GraphQL site. I use graphql 16.3 and apollo-server 2.25.3. I don't know what the message told me what to fix. Help me please. Thank you guys so much!


Solution

  • From their documentation it seems that apollo-server 2 don't support graphql >15

    https://www.apollographql.com/docs/apollo-server/migration/

    I would either migrate to apollo-server 3 or downgrade graphql to version 15.