'Apollo Server and TypeScript: Type 'GraphQLApi' has no properties in common with type 'DataSource<object>'
I'm setting up an interface between our NextJS Front and a series of backends. The interface will convert the various backs' REST or GraphQL APIs into a unitary GraphQL API. I'm using the library apollo-datasource-graphql to translate a back that offers a GraphQL API into a datasource to use with Apollo Server. I'm running into a fair number of TypeScript issues. At present TS complains about my definition of the Apollo data sources
index.ts:10:25 - error TS2559: Type 'InterfaceGraphQLApi' has no properties in common with type 'DataSource<object>'.
10 dataSources: () => ({ gqlApi: new InterfaceGraphQLApi() })
~~~~~~
node_modules/apollo-server-core/dist/graphqlOptions.d.ts:31:5
31 [name: string]: DataSource<TContext>;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The expected type comes from this index signature.
here
const server = new ApolloServer({
typeDefs,
resolvers,
dataSources: () => ({ gqlApi: new InterfaceGraphQLApi() })
});
where InterfaceGraphQLApi starts thusly
import { GraphQLDataSource } from "apollo-datasource-graphql";
export default class InterfaceGraphQLApi extends GraphQLDataSource {
baseURL = "http://localhost:4545/admin/api";
In the source files for Apollo-datasource-graphql (node_modules/src/GraphQLDataSource.ts) I see
export class GraphQLDataSource<TContext = any> {
So it seems that I could pass some kind of type parameter, which would be the same as Datasource<object> I might be OK? But I'm far out of my TypeScript/Apollo knowledge zone, so I'm wandering lost here. Any guidance much appreciated!
Solution 1:[1]
<input type="date" name="begin"
placeholder="dd-mm-yyyy" value=""
min="1997-01-01" max="2030-12-31">
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Krunal Solanki |
