mirror of
https://github.com/vale981/apollo-server
synced 2025-03-06 02:01:40 -05:00
![]() … version This PR should hopefully correct some typing issues we are currently facing. The problem: - this package references v5.0.1 for @types/koa-bodyparser - when we start our server that also uses koa-bodyparser for non-graphql routes, the type for koa.Request sets the "body" field to: ``` declare module "koa" { interface Request { body: {} | null | undefined; rawBody: {} | null | undefined; } } ``` Which breaks our type defs for koa-bodyparser as we actually want "body" to be set to "any." The v5.0.1 that was originally placed here is no longer "latest" and they have published a new v4 version that has the correct typing for koa-bodyparser (setting body to any). - https://www.npmjs.com/package/@types/koa-bodyparser <!-- Thanks for filing a pull request on GraphQL Server! Please look at the following checklist to ensure that your PR can be accepted quickly: --> TODO: * [ ] Update CHANGELOG.md with your change (include reference to issue & this PR) * [x] Make sure all of the significant new logic is covered by tests * [x] Rebase your changes on master so that they can be merged easily * [x] Make sure all tests and linter rules pass |
||
---|---|---|
.. | ||
src | ||
.npmignore | ||
jest.config.js | ||
package.json | ||
README.md | ||
tsconfig.json |
title | description |
---|---|
Koa | Setting up Apollo Server with Koa |
This is the Koa integration of GraphQL Server. Apollo Server is a community-maintained open-source GraphQL server that works with many Node.js HTTP server frameworks. Read the docs. Read the CHANGELOG.
npm install apollo-server-koa@rc graphql
Koa
const Koa = require('koa');
const { ApolloServer, gql } = require('apollo-server-koa');
// Construct a schema, using GraphQL schema language
const typeDefs = gql`
type Query {
hello: String
}
`;
// Provide resolver functions for your schema fields
const resolvers = {
Query: {
hello: () => 'Hello world!',
},
};
const server = new ApolloServer({ typeDefs, resolvers });
const app = new Koa();
server.applyMiddleware({ app });
app.listen({ port: 4000 }, () =>
console.log(`🚀 Server ready at http://localhost:4000${server.graphqlPath}`),
);
Principles
GraphQL Server is built with the following principles in mind:
- By the community, for the community: GraphQL Server's development is driven by the needs of developers
- Simplicity: by keeping things simple, GraphQL Server is easier to use, easier to contribute to, and more secure
- Performance: GraphQL Server is well-tested and production-ready - no modifications needed
Anyone is welcome to contribute to GraphQL Server, just read CONTRIBUTING.md, take a look at the roadmap and make your first PR!