기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.
GraphQL 스키마용 지시문으로 작업
다음과 같은 명령을 사용하여 이미 지시문이 있는 GraphQL 스키마에서 시작할 수 있습니다.
neptune-for-graphql \ --input-schema-file
(your GraphQL schema file with directives)
\ --create-update-aws-pipeline \ --create-update-aws-pipeline-name (name for your new GraphQL API) \ --create-update-aws-pipeline-neptune-endpoint(empty Neptune database endpoint)
:(port number)
\ --output-resolver-query-https
유틸리티에서 생성한 지시문을 수정하거나 GraphQL 스키마에 자체 지시문을 추가할 수 있습니다. 지시문으로 작업하는 몇 가지 방법은 다음과 같습니다.
변형이 생성되지 않도록 유틸리티 실행
GraphQL API에서 유틸리티가 변형을 생성하지 않도록 하려면 neptune-for-graphql
명령의 --output-schema-no-mutations
옵션을 사용합니다.
@alias
지시문
이 @alias
지시문은 GraphQL 스키마 유형 또는 필드에 적용할 수 있습니다. 그래프 데이터베이스와 GraphQL 스키마 간에 서로 다른 이름을 매핑합니다. 구문은 다음과 같습니다.
@alias(property:
(property name)
)
아래 airport
예시는 Airport
GraphQL 유형에 매핑된 그래프 데이터베이스 노드 레이블이고, desc
는 description
필드에 매핑된 그래프 노드 속성입니다(항공 경로 예제 참조).
type Airport @alias(property: "airport") { city: String description: String @alias(property: "desc") }
표준 GraphQL 형식을 지정하려면 파스칼 표기법 유형 이름과 카멜 표기법 필드 이름을 사용합니다.
@relationship
지시문
이 @relationship
지시문은 중첩된 GraphQL 유형을 그래프 데이터베이스 엣지에 매핑합니다. 구문은 다음과 같습니다.
@relationship(edgeType:
(edge name)
, direction:(IN or OUT)
)
다음은 명령 예제입니다.
type Airport @alias(property: "airport") { ... continentContainsIn: Continent @relationship(edgeType: "contains", direction: IN) countryContainsIn: Country @relationship(edgeType: "contains", direction: IN) airportRoutesOut(filter: AirportInput, options: Options): [Airport] @relationship(edgeType: "route", direction: OUT) airportRoutesIn(filter: AirportInput, options: Options): [Airport] @relationship(edgeType: "route", direction: IN) }
Todo 예제와 항공 노선 예제 모두에서 @relationship
지시문을 확인할 수 있습니다.
@graphQuery
및 @cypher
지시문
openCypher 쿼리를 정의하여 필드 값을 해결하거나 쿼리를 추가하거나 변형을 추가할 수 있습니다. 예를 들어 이렇게 하면 Airport
유형에 새 outboundRoutesCount
필드가 추가되어 아웃바운드 경로를 계산할 수 있습니다.
type Airport @alias(property: "airport") { ... outboundRoutesCount: Int @graphQuery(statement: "MATCH (this)-[r:route]->(a) RETURN count(r)") }
다음은 새 쿼리 및 변형의 예시입니다.
type Query { getAirportConnection(fromCode: String!, toCode: String!): Airport \ @cypher(statement: \ "MATCH (:airport{code: '$fromCode'})-[:route]->(this:airport)-[:route]->(:airport{code:'$toCode'})") } type Mutation { createAirport(input: AirportInput!): Airport @graphQuery(statement: "CREATE (this:airport {$input}) RETURN this") addRoute(fromAirportCode:String, toAirportCode:String, dist:Int): Route \ @graphQuery(statement: \ "MATCH (from:airport{code:'$fromAirportCode'}), (to:airport{code:'$toAirportCode'}) \ CREATE (from)-[this:route{dist:$dist}]->(to) \ RETURN this") }
참고로 RETURN
을 생략하면 해석기는 this
키워드를 반환 범위로 간주합니다.
Gremlin 쿼리를 사용하여 다음과 같이 쿼리 또는 변형을 추가할 수도 있습니다.
type Query { getAirportWithGremlin(code:String): Airport \ @graphQuery(statement: "g.V().has('airport', 'code', '$code').elementMap()") # single node getAirportsWithGremlin: [Airport] \ @graphQuery(statement: "g.V().hasLabel('airport').elementMap().fold()") # list of nodes getCountriesCount: Int \ @graphQuery(statement: "g.V().hasLabel('country').count()") # scalar }
현재 Gremlin 쿼리는 스칼라 값을 반환하거나 단일 노드의 elementMap()
또는 노드 목록의 elementMap().fold()
를 반환하는 쿼리로 제한됩니다.
@id
지시문
@id
지시문은 id
그래프 데이터베이스 엔터티에 매핑된 필드를 식별합니다. Amazon Neptune과 같은 그래프 데이터베이스에는 대량 가져오기 중에 할당되거나 자동 생성되는 노드 및 엣지의 고유한 id
가 항상 포함되어 있습니다. 예:
type Airport { _id: ID! @id city: String code: String }
예약 유형, 쿼리 및 변형 이름
이 유틸리티는 쿼리와 변형을 자동으로 생성하여 작동하는 GraphQL API를 생성합니다. 이러한 이름의 패턴은 해석기에서 인식되며 예약됩니다. 유형 Airport
및 연결 유형 Route
의 예는 다음과 같습니다.
Options
유형이 예약되어 있습니다.
input Options { limit: Int }
filter
및 options
함수 파라미터가 예약되어 있습니다.
type Query { getNodeAirports(filter: AirportInput, options: Options): [Airport] }
쿼리 이름의 getNode 접두사는 예약되고 createNode
, updateNode
, deleteNode
, connectNode
, deleteNode
, updateEdge
, deleteEdge
와 같은 변형 이름의 접두사가 예약됩니다.
type Query { getNodeAirport(id: ID, filter: AirportInput): Airport getNodeAirports(filter: AirportInput): [Airport] } type Mutation { createNodeAirport(input: AirportInput!): Airport updateNodeAirport(id: ID!, input: AirportInput!): Airport deleteNodeAirport(id: ID!): Boolean connectNodeAirportToNodeAirportEdgeRout(from: ID!, to: ID!, edge: RouteInput!): Route updateEdgeRouteFromAirportToAirport(from: ID!, to: ID!, edge: RouteInput!): Route deleteEdgeRouteFromAirportToAirport(from: ID!, to: ID!): Boolean }
GraphQL 스키마에 변경 사항 적용
GraphQL 소스 스키마를 수정하고 유틸리티를 다시 실행하여 Neptune 데이터베이스에서 최신 스키마를 가져올 수 있습니다. 유틸리티는 데이터베이스에서 새 스키마를 발견할 때마다 새 GraphQL 스키마를 생성합니다.
GraphQL 소스 스키마를 수동으로 편집하고 Neptune 데이터베이스 엔드포인트 대신 소스 스키마를 입력으로 사용하여 유틸리티를 다시 실행할 수도 있습니다.
마지막으로 다음 JSON 형식을 사용하여 파일에 변경 내용을 넣을 수 있습니다.
[ { "type": "
(GraphQL type name)
", "field": "(GraphQL field name)
", "action": "(remove or add)
", "value": "(value)
" } ]
예:
[ { "type": "Airport", "field": "outboundRoutesCountAdd", "action": "add", "value":"outboundRoutesCountAdd: Int @graphQuery(statement: \"MATCH (this)-[r:route]->(a) RETURN count(r)\")" }, { "type": "Mutation", "field": "deleteNodeVersion", "action": "remove", "value": "" }, { "type": "Mutation", "field": "createNodeVersion", "action": "remove", "value": "" } ]
그런 다음 명령의 --input-schema-changes-file
파라미터를 사용하여 이 파일에서 유틸리티를 실행하면 유틸리티가 변경 내용을 한 번에 적용합니다.