브렌쏭의 Veritas_Garage

문맥이 너무해 본문

[Project_만들다]/[Project_자아내다]

문맥이 너무해

브렌쏭 2022. 4. 7. 13:54

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

 

API Reference: ApolloServer

app.use('*', jwtCheck, requireAuth, checkScope);

www.apollographql.com

Apollo Server에서 API를 제작하다 보면, 스키마를 지정하고 만들 수 있다. 

constructor

Returns an initialized ApolloServer instance.

Takes an options object as a parameter. Supported fields of this object are described below.

const server = new ApolloServer({
    typeDefs,
    resolvers,
    context
});

오늘 파고들 주제는 저 옵션들 중 context이다.

  • An object that's passed to every resolver that executes for a particular operation.
    (특정 동작을 실행시키는 모든 리졸버에서 통과된 객체, 혹은 객체를 만드는 함수)
  • This enables resolvers to share helpful context, such as a database connection.
  • Certain fields are added to this object automatically, depending on which Node.js middleware your server uses.
  • For more details, see The context argument.
데이터베이스 연결과 같은 유용한 context를 리졸버들이 공유할 수 있도록 한다

The Context Argument

https://www.apollographql.com/docs/apollo-server/data/resolvers/#the-context-argument

 

Resolvers

How Apollo Server processes GraphQL operations

www.apollographql.com

  • The context argument is useful for passing things that any resolver might need, like authentication scope, database connections, and custom fetch functions.
  • If you're using dataloaders to batch requests across resolvers, you can attach them to the context as well.
  • Resolvers should never destructively modify the context argument. This ensures consistency across all resolvers and prevents unexpected errors.
  • To provide an initial context to your resolvers, add a context initialization function to the ApolloServer constructor.
  • This function is called with every request, so you can customize the context based on each request's details (such as HTTP headers).
Comments