-
Notifications
You must be signed in to change notification settings - Fork 5
Apollo Server Execution
Ahrim Yang edited this page Nov 30, 2020
·
5 revisions
์์ฑ์: J113 ์์๋ฆผ
-
typeDefs
- GraphQL ์ schema ๋ฅผ ๋ํ๋ด๋ Document or documents
- gql ํ๊ทธ๋ฅผ ์ฌ์ฉํ์ฌ SDL(Schema Definition Language)๋ก ๋ํ๋
-
resolvers
- ๊ฐ๊ฐ์ schema field๋ฅผ ์ฑ์ฐ๊ธฐ ์ํ function๋ค์ map
-
context
- ๋ชจ๋ resolver์๊ฒ ์ ๋ฌ๋๋ object ๋๋ object๋ฅผ ๋ฐํํ๋ ํจ์
-
apollo-server-express
์์๋req
,res
๊ฐ ์๋์ผ๋ก ์ถ๊ฐ๋์ด์์
-
introspection
- schema ์ ๋ด์ฉ์ client๊ฐ ํ์ธํ ์ ์์
- default ๋ true, NODE_ENV๊ฐ production์ด๋ฉด false
-
schemaDirectives
- map of custom schema directives
-
schema
- GrphQL ์ Schema
- Apollo Server๊ฐ typeDefs ์ resolvers๋ก๋ถํฐ ์์ฑํ๊ธฐ ๋๋ฌธ์ ๋๋ถ๋ถ์ ์ํฉ์์๋ ๋ฐ์ดํฐ ํ์ ์์
- ์ฃผ๋ก Apollo Federation๊ณผ ๊ฐ์ด ์ฌ์ฉ๋จ
-
persistedQueries
- caching ๊ณผ ๊ด๋ จ๋ ์ต์
- APQ(Automated Persisted Queries)
-
subscriptions
- subscription ๊ด๋ จ ์ต์
-
path
,keepAlive
.onConnect
,onDisconnect
์ ๋ช ์ํด์ค
rootValue
validationRules
-
cors
-
apollo-server
๋ฅผ ์ฌ์ฉํ ๋ CORS ์ค์ -
apollo-server-{Node.js middleware}
๊ฐ์ ๋ค๋ฅธ ๋ฏธ๋ค์จ์ด์ ํตํฉํ์ฌ ์ฌ์ฉํ ๋๋ ๊ฐ๊ฐ์ ๋ฏธ๋ค์จ์ด ํ๊ฒฝ์ ๋ง๊ฒ ์ค์ ํด์ค๋ค. (applyMiddleware)
-
cacheControl
formatError
formatResponse
apollo
plugins
stopOnTerminationSignals
playground
debug
logger
mocks
mockEntireSchema
const typeDefs = gql`
# A library has a branch and books
type Library {
branch: String!
books: [Book!]
}
# A book has a title and author
type Book {
title: String!
author: Author!
}
# An author has a name
type Author {
name: String!
}
# Queries can fetch a list of libraries
type Query {
libraries: [Library]
}
`;
- Field names: camelCase
- Type names: PascalCase
- Enum names Pascalcase
- Enum values ALL_CAPS
// Resolver map
const resolvers = {
Query: {
libraries(parent, args, context, info) {
// Return array of libraries
return libraries;
},
},
Library: {
books(parent, args, context, info) {
// Filter the array of books to only include
// books that are located at the correct branch
return books.filter((book) => book.branch === parent.branch);
},
},
Book: {
// The parent resolver (Library.books) returns an object with the
// author's name in the "author" field. Return a JSON object containing
// the name, because this field expects an object.
author(parent, args, context, info) {
return {
name: parent.author,
};
},
},
// Because Book.author returns an object with a "name" field,
// Apollo Server's default resolver for Author.name will work.
// We don't need to define one.
// Author: {
// name(parent, args, context, info) {
// return parent.name;
// },
// },
};
- ApolloServer instance๋ฅผ ์์ฑํ ๋ ์ค์ ํ ๊ฐ์ ๋ฐ๋ผ์ ์๋์ ๊ฐ์ instance๊ฐ ์์ฑ๋จ
ApolloServer {
graphqlPath: '/graphql',
requestOptions: {
tracing: true,
cache: InMemoryLRUCache { store: [LRUCache] },
persistedQueries: { cache: [PrefixingKeyValueCache] }
},
plugins: [
{ requestDidStart: [Function: requestDidStart] },
{ requestDidStart: [Function: requestDidStart] }
],
toDispose: Set(2) { [Function (anonymous)], [Function (anonymous)] },
config: {
typeDefs: { kind: 'Document', definitions: [Array], loc: [Object] },
resolvers: {
Query: [Object],
Library: [Object],
Book: [Object],
Upload: Upload
},
tracing: true
},
logger: Logger {},
apolloConfig: { graphVariant: 'current' },
parseOptions: {},
context: undefined,
uploadsConfig: {},
subscriptionServerOptions: { path: '/graphql' },
subscriptionsPath: '/graphql',
playgroundOptions: { version: '1.7.33', settings: undefined },
schema: GraphQLSchema {
__validationErrors: [],
description: undefined,
extensions: undefined,
astNode: undefined,
extensionASTNodes: [],
_queryType: Query,
_mutationType: undefined,
_subscriptionType: undefined,
_directives: [ @cacheControl, @include, @skip, @deprecated, @specifiedBy ],
_typeMap: [Object: null prototype] {
Library: Library,
String: String,
Book: Book,
Author: Author,
Query: Query,
CacheControlScope: CacheControlScope,
Upload: Upload,
Int: Int,
Boolean: Boolean,
__Schema: __Schema,
__Type: __Type,
__TypeKind: __TypeKind,
__Field: __Field,
__InputValue: __InputValue,
__EnumValue: __EnumValue,
__Directive: __Directive,
__DirectiveLocation: __DirectiveLocation
},
_subTypeMap: [Object: null prototype] {},
_implementationsMap: [Object: null prototype] {}
schemaDerivedData: Promise {
{
schema: [GraphQLSchema],
schemaHash: '',
extensions: [],
documentStore: [InMemoryLRUCache]
}
},
cors: undefined,
onHealthCheck: undefined
}
- ๋ฌธ์์ด์ AST(Abstract Syntax Tree)๋ก parsing ํ๋ค
- ์ด ๊ณผ์ ์์ ์๋ฌ๊ฐ ๋๋ฉด ์คํ์ ์ค๋จํ๊ณ client์๊ฒ ์๋ฌ๋ฅผ returnํ๋ค.
- type, arguments, return field ๋ฑ์ด ์ ์๋ schema ์ ๋ง๋์ง ํ์ธํ๋ค.
๐กHome
- Apollo References
- Schema Directives
- Apollo Client - Local State
- GraphQL Execution
- Apollo Server Execution
- Apollo Client Cache
- Apollo Client Execution
- Mongoose-Populate