Document usage of server creation in typescript
See original GitHub issueApollo server doesn’t provide any documentation for usage with TypeScript, whilst this wouldn’t normally be an issue for most projects the server uses some advanced types which aren’t obvious to consume.
Example
const server = new ApolloServer({
typeDefs,
resolvers,
dataSources: (): **???** => {
return {
blogPostApi: new BlogPostApi(
config.prismic.url,
config.prismic.accessToken
)
};
}
});
First pass this looks like it should be DataSource<IDataSources>
where IDataSource is something like;
interface IDataSources {
blogPostApi: IBlogPostApi;
}
But returns;
src/index.ts:47:7 - error TS2322: Type '{ blogPostApi: BlogPostApi; }' is not assignable to type 'DataSource<IDataSources>'.
Object literal may only specify known properties, and 'blogPostApi' does not exist in type 'DataSource<IDataSources>'.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:10
- Comments:10 (1 by maintainers)
Top Results From Across the Web
Using Node.js, Typescript, and Express to Build a Web Server
This guide shows you how to configure a Node.js, TypeScript, and Express dev environment, after which you will learn how to build a...
Read more >Node.js TypeScript #7. Creating a server and receiving requests
In this article, we learned how to create a server and handle incoming requests, including file uploads. The request and response objects are ......
Read more >Node.js and TypeScript Tutorial: Build a CRUD API - Auth0
Learn how to use TypeScript to build a feature-complete Express API. Tutorial on how to use TypeScript with Express to create, read, update, ......
Read more >Documentation - TypeScript Tooling in 5 minutes
A tutorial to understand how to create a small website with TypeScript.
Read more >How to set up TypeScript with Node.js and Express
Create a package.json file · Create a minimal server with Express · Installing TypeScript · Generating tsconfig.json · Create an Express server with ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Not shown here, but I pass the base datasource into buildDataSources() and then through to the MyDataSource wrapper object.
The Apollo Server 4 docs use TypeScript by default (and also let you see code examples as JavaScript).
I agree with you that using dataSources was strange from a typing perspective (for example, it meant that the type of the context value returned from your
context
function didn’t match the type of the context value available to resolvers and plugins); the dataSources option has been removed from Apollo Server 4 primarily for this reason.