1
votes

Using Apollo-Server-Express, I want to wrap a REST API with GraphQL. I'm starting with the free to use SWAPI (Star Wars API). I can't find anything about server side fetching with cursor paging using apollo-server-express. The only thing that I found that could be a possibility since it's for the Apollo Client is fetchMore. Any help would be greatly appreciated. Here's my code:

schema.js

// Imports: GraphQL
import { makeExecutableSchema } from 'graphql-tools';

// Imports: GraphQL TypeDefs & Resolvers
import TYPEDEFS from './types.js';
import RESOLVERS from './resolvers.js';


// GraphQL: Schema
const SCHEMA = makeExecutableSchema({
  typeDefs: TYPEDEFS,
  resolvers: RESOLVERS
});

export default SCHEMA;

types.js

const TYPEDEFS = `
    type Query {
    getFilm(id: ID): Film
    getAllFilms: [Film]
}

type Film {
    title: String!
    episode_id: Int!
    opening_crawl: String
    director: String
    producer: String
    release_date: String
    characters: [Person]
    planets: [Planet]
    starships: [Starship]
    vehicles: [Vehicle]
    species: [Species]
    created: String
    edited: String
    url: String
    }
}`

export default TYPEDEFS;

resolvers.js

import fetch from 'node-fetch';


const RESOLVERS = {
    Query: {
        // Search for a Film by ID
        getFilm: async (parent, args) => {
            const response = await
            fetch(`https://swapi.co/api/films/${args.id}`);
            return response.json();
        },
        getAllFilms: async (parent, args) => {
            const response = await
            fetch(`https://swapi.co/api/films/`);
            return response.json();
        }
    }
};

export default RESOLVERS;
1

1 Answers

0
votes

I believe apollo-server does not provide cursor pagination out of the box.

You can either implement it yourself. Or you can use(or get inspired) by the one that Relay uses.

And according to Apollo client if you use Relay style cursor pagination the client has support for it.