
Walder는 분산 지식 그래프 위에 웹 사이트 또는 웹 API를 쉽게 설정할 수있는 방법을 제공합니다. 지식 그래프는 해당 데이터의 의미와 함께 데이터를 통합합니다. 이로 인해 독립적 인 당사자가 유지하거나 호스팅하더라도 여러 지식 그래프의 데이터를 결합 할 수 있습니다. 지식 그래프는 솔리드 포드, SPARQL 엔드 포인트, 트리플 패턴 조각 인터페이스, RDF 파일 등을 통해 호스팅 될 수 있습니다. Walder는 콘텐츠 협상을 사용하여 HTML, RDF 및 JSON-LD를 통해 이러한 지식 그래프의 데이터를 클라이언트에 사용할 수있게합니다. 사용자는 Walder가 사용하는 데이터 와이 데이터를 처리하는 방법을 구성 파일로 정의합니다. Walder와 함께 어떤 API가 만들어 졌는지 알아보십시오.
목차
yarn global add walder 통해 전 세계적으로 Walder를 설치하십시오.
개발을 위해 다음 단계를 따르십시오.
yarn install 통해 종속성을 설치하십시오.$ yarn global add file:$(pwd) 를 통해 전 세계적으로 Walder를 설치하십시오. Walder는 CLI 및 JavaScript 라이브러리로 제공됩니다.
Usage: walder [options]
Options:
-v, --version output the version number
-c, --config < configFile > YAML configuration file input
-p, --port [portNumber] server port number (default: 3000)
-l, --log [level] enable logging and set logging level (one of [error, warn, info, verbose, debug]) (default: " info " )
--no-cache disable Comunica default caching
--lenient turn Comunica errors on invalid data into warnings
-h, --help output usage information // From the root directory
const Walder = require ( '.' ) ;
const configFilePath = 'path/to/configfile' ;
const port = 9000 ; // Defaults to 3000
const logging = 'info' ; // Defaults to 'info'
const cache = false ; // Defaults to true
const lenient = true ; // Defaults to false
const walder = new Walder ( configFilePath , { port , logging , cache , lenient , cwd } ) ;
walder . activate ( ) ; // Starts the server
walder . deactivate ( ) ; // Stops the serverOpenAPI 3.0 사양에 따라 Yaml에 구성 파일을 작성합니다. 구성 파일에는 다음 구조가 있어야합니다.
openapi : 3.0.2
info : # OpenAPI metadata
title : ' Example site '
version : 0.1.0
x-walder-resources : # Directories used by Walder - OPTIONAL
root : # Path to the root folder of the directories used by Walder (absolute or relative to the directory containing the config file) - OPTIONAL (default: .)
views : # Path to directory containing view template files (absolute or relative to the root folder) - OPTIONAL (default: views)
pipe-modules : # Path to directory containing local pipe modules (absolute or relative to the root folder) - OPTIONAL (default: pipe-modules)
public : # Path to directory containing all files that should be available statically (e.g. stylesheets) (absolute or relative to the root folder) - OPTIONAL (default: public)
layouts : # Path to directory containing all layout template files that can be used by view template files (absolute or relative to the root folder) - OPTIONAL (default: layouts)
x-walder-datasources : # Default list of data sources
- ... # E.g. link to SPARQL endpoint or a GraphQL-LD query
paths : # List of path entries
path-entry-1 :
...
path-entry-2 :
...
x-walder-errors : # Default error page views - status codes with files containing the HTML view template (absolute path or relative to the views directory)
404 : ...
500 : ...
... 구성 파일의 x-walder-resources 키에는 Walder가 사용하는 디렉토리로의 경로가 포함되어 있습니다. 이 키와 값은 선택 사항입니다. 사용자가 경로를 제공하지 않으면 Walder는 구성 파일의 디렉토리와 관련하여 다음 기본값을 사용합니다.
root : .
views : views
pipe-modules : pipe-modules
public : public
layouts : layouts Walder가 잘못된 파일을 공개하지 못하게하려면 사용자가 public 분야로의 경로를 제공하지 않으면 Walder는 현재 작업 디렉토리 에서이 디렉토리를 찾지 못하고 해당 디렉토리를 사용하는 경우 새 디렉토리를 public 합니다.
경로 항목은 경로를 정의하고 다음과 같은 구조를 가지고 있습니다.
path : # The path linked to this query
request : # The HTTP request type (GET, POST, etc.)
summary : ... # Short description
parameters : # Path variables/Query parameters
- in : ... # 'path' or 'query'
name : ... # Name of the parameter
schema :
type : ... # Type of the parameter
description : ... # Description of the parameter
x-walder-query :
graphql-query : ... # One or more GraphQL queries
json-ld-context : ... # The JSON-LD corresponding to the GraphQL query
sparql-query : ... # One or more SPARQL queries
json-ld-frame : ... # A JSON-LD frame that should be applied to the result of a SPARQL query
options : # Global options that will be applied to all the graphql-queries of this path (OPTIONAL)
datasources : # Query specific datasources (OPTIONAL)
additional : ... # Boolean stating that the following datasources are meant to be used on top of the default ones
sources : # List of query specific datasources
- ... # E.g. link to SPARQL endpoint
x-walder-postprocessing : # The (list of) pipe modules used for postprocessing
module-id : # Identifier of the pipe module
source : ... # Path leading to source code of the pipe module (absolute path or relative to the pipe-modules directory)
parameters : # the parameters for the pipe module (OPTIONAL)
- _data # (DEFAULT) this gives all the data, but all paths in the data object are supported (e.g. _data.0.employee)
- ... # Additional parameters if your function supports those (OPTIONAL)
responses : # Status codes with files containing the HTML view template (absolute path or relative to the views directory)
200 : ... # (REQUIRED)
500 : ... # (OPTIONAL)다음 명령은 예제 구성 파일을 사용하여 포트 3000 (기본값)에서 서버를 시작합니다.
$ walder -c example/config.yaml
이것은 localhost:3000 에서 다음 경로로 서버를 시작합니다.
위의 경로 항목에서 사용자는 Walder가 해당 경로의 모든 쿼리에 대해 사용하는 글로벌 (선택적) 식별자로 정의 options . 우리는 선택할 수있는 두 가지 옵션이 있습니다 : sort 및 remove-duplicates . 주어진 구문으로 :
options :
sort : # Enable sorting on the data (OPTIONAL)
object : # JSONPath to the object you want to sort for
selectors : # The values inside the object over which you want to sort
- ... # The default option when you want ascending order, just give the value (JSONPath notation supported for further nesting)
- value : ... # When you want descending order, specify the value/order (JSONPath notation supported for further nesting)
order : desc
remove-duplicates : # Enable the removal of duplicates of the data (OPTIONAL)
object : ... # The JSONPath tot the object that you want to compare
value : ... # The value that has to be compared to determine whether it's duplicate (JSONPath notation is also supported for further nesting) 전체 경로에 대해 options 전역이되기를 원하지 않으면 쿼리 당 options 정의 할 수 있습니다.
path : # The path linked to this query
request : # The HTTP request type (GET, POST, etc.)
summary : ... # Short description
parameters : # Path variables/Query parameters
- in : ... # 'path' or 'query'
name : ... # Name of the parameter
schema :
type : ... # Type of the parameter
description : ... # Description of the parameter
x-walder-query :
graphql-query : ... # One or more GraphQL queries
name :
query : ... # The GraphQL query
options : # options that will be applied only to this specific graphql-query (OPTIONAL)
...다음 명령은이 구성 파일을 사용하여 서버를 시작합니다.
$ walder -c example/config-sorting-duplicates.yaml
이것은 localhost:3000 에서 다음 경로로 서버를 시작합니다.
$ref 키워드를 사용하여 여러 파일로 구성 파일을 분할 할 수 있습니다. 우리는 참조를 사용하는 방법을 설명하는 OpenApi 3.0 사양을 따릅니다.
처음 참조되면 구성 파일의 디렉토리에서 시작하는 경로를 사용해야하지만 참조 파일에 참조 자체가있는 경우 아래 그림과 같이 자체 위치와 관련된 경로를 사용할 수 있습니다.
경로를 참조하는 실제 구성 파일
openapi : 3.0.2
info :
title : ' Example site '
version : 0.1.0
x-walder-resources :
path : ./
views : views
pipe-modules : pipeModules
public : public
x-walder-datasources :
- http://fragments.dbpedia.org/2016-04/en
paths :
/music/{musician} :
$ref : ' ./paths/music_musician.yaml '
/movies/{actor} :
$ref : ' ./paths/movies_actor.yaml '
x-walder-errors :
404 :
description : page not found error
x-walder-input-text/html : error404.html
500 :
description : internal server error
x-walder-input-text/html : error500.html 아래는 ./example/paths/movies_actor.yaml 자체 위치와 관련하여 경로를 참조하십시오.
get :
summary : Returns a list of the all movies the given actor stars in
parameters :
- in : path
name : actor
required : true
schema :
type : string
description : The target actor
x-walder-query :
$ref : ' ../walderQueryInfo/movies_actor_info.yaml '
responses :
200 :
description : list of movies
x-walder-input-text/html : movies.pug
컨텐츠 협상을 사용하여 Walder는 다음과 같은 출력 형식을 사용할 수 있습니다.
Walder는 GraphQL-Ld-Comunica를 사용하여 GraphQL 쿼리와 @comunica/query-sparql을 실행하여 sparql 쿼리를 실행합니다. GraphQL-LD 쿼리의 결과는 JSON 데이터입니다. Walder는 먼저 JSON-LD로 변환합니다. 이를 통해 콘텐츠 협상 중에 다른 RDF 형식으로 전환 할 수 있습니다. SPARQL 쿼리의 결과는 다양한 쿼드입니다. JSON-LD 프레임이 지정되면 쿼드는 JSON-LD로 변환됩니다. 콘텐츠 협상의 중요성으로 인해 구성 쿼리 만 지원됩니다.
Walder는 Consolidate를 사용하여 주어진 템플릿의 해당 엔진을 자동으로 검색합니다. 이는 지원되는 템플릿 엔진이 통합에 의존한다는 것을 의미합니다.
Pug는 다른 경로에 다른 템플릿 엔진을 사용할 수 있으며 Pug는 하나의 경로의 HTML을 렌더링하고 핸들 바는 다른 경로의 HTML을 렌더링합니다. Walder는 주어진 템플릿의 파일 확장을 보면이 작업을 수행합니다.
템플릿은 레이아웃뿐만 아니라보기에도 사용할 수 있습니다. 따라서 구별하기 위해 템플릿 및 레이아웃 템플릿을 볼 수 있습니다.
경로의 구성 파일에 지정된 쿼리의 결과는보기 템플릿에서 데이터로 렌더링 할 수 있습니다.
data 지정된 객체가 포함되어 있습니다. GraphQL-LD 쿼리의 경우 쿼리가 단수화되지 않는 한 각 객체는 배열이됩니다. Songs.HandleBars는이 구성 파일의 Route /music/{musician} 의 단일 쿼리 결과의 소비의 예입니다. songs_movies.handlebars는이 구성 파일의 Route /artist/{artist} 의 두 쿼리 결과의 소비의 예입니다.
SPARQL 쿼리의 경우 JSON-LD 프레임이 지정되지 않은 경우 각 객체는 쿼드 배열입니다. 그렇지 않으면 JSON-LD 객체가 될 것입니다.
레이아웃을 사용하는 것은 경로 별 뷰 템플릿에서 반복을 피하는 좋은 방법입니다. 여러 경로에 나타나기위한 헤더, 바닥 글, 내비게이션 바 및 기타 내용과 같은 재사용 가능한 HTML 구조가 레이아웃 파일 에 지정된 것이 좋습니다.
레이아웃 템플릿 파일은 전면 메타 데이터 필드 layout 통해보기 템플릿 파일에 지정할 수 있습니다. 구성 파일에 정의 된 layouts 위치에서 사용할 수있는 파일 이름이 포함되어야합니다. 파일 이름 앞에 상대 경로가 포함될 수 있습니다.
예제 템플릿 파일 레이아웃 지정 :
---
layout: my-layout.pug
---
// view template continues here
Walder는 View Template 파일에서 생성 된 내부 HTML 컨텐츠를 content 라는 객체로 레이아웃 템플릿 파일로 전달한 데이터에 넣습니다.
레이아웃 템플릿 파일은 또 다른 템플릿입니다. 일반적으로 이러한 내부 HTML 내용을 선택 위치에서 확장합니다.
간단한 퍼그 예제 (Mind the !{content} ) :
doctype html
html(lang="en")
head
title I'm based on a layout
body !{content}
Walder는 쿼리 결과 외에도 뷰 템플릿에 지정된 전면 메타 데이터를 데이터에 대한 추가 속성으로 추가합니다.
각 추가 속성의 이름은 제공된 메타 데이터 필드 이름과 같습니다. 다음 메타 데이터 필드는 layout , content , data 및 여러 쿼리가있는 경로에서 쿼리에 할당 된 이름입니다 (위 참조).
이 속성은보기 템플릿과 레이아웃 템플릿에 사용할 수 있습니다.
예제보기 템플릿 파일 전면 메타 데이터 필드를 지정하고 해당 필드를 읽습니다 (Mind the #{a1} ) :
--
a1: Value for FrontMatter attribute a1!
---
doctype html
html(lang="en")
body
main a1: #{a1}
예제 템플릿 파일보기, 레이아웃 템플릿을 지정하고 다른 전면 메타 데이터 필드를 지정합니다.
---
layout: layout-fm.pug
a2: Value for FrontMatter attribute a2!
---
main Lorem ipsum
예제 해당 레이아웃 템플릿 (Layout-Fm.pug) 해당 필드를 읽습니다 (Mind the #{a2} ) :
doctype html
html(lang="en")
head
if a2
title #{a2}
body !{content}
구성 파일을 구문 분석하는 동안 Walder는 입력의 정확성과 완전성을 검증합니다. Walder가 전체 구성 파일을 구문 분석하고 오류를 찾았을 때 Walder는 모든 오류와 종료를 반환합니다.
현재 Walder는 다음을 확인합니다.
200~x-walder-input-text/html 항목의 기존 파일 만 언급합니다. Walder는 오류 페이지를 특정 HTTP 상태 코드에 바인딩합니다. 기본 오류 페이지를 정의 할 수 있지만 해당 경로 항목의 responses 키에 추가하여 경로 특정 오류 페이지도 정의 할 수 있습니다.
404 : 페이지를 찾을 수 없습니다500 : 내부 서버 오류 500 : 주어진 파이프 모듈을 적용 할 수 없습니다. 404 : 예상 변수가 제공되지 않았습니다500 : 주어진 쿼리를 실행할 수 없습니다다음 명령을 사용하여 Walder를 실행할 때 :
$ walder -c example/config-errors.yaml
다음 경로는 오류로 이어집니다.
404 (글로벌 : 페이지 찾기 없음)500 (파이프 모듈 : 주어진 파이프 모듈을 적용 할 수 없음)500 (GraphQL-Ld : 주어진 쿼리를 실행할 수 없습니다) 다음 구성 파일 발췌문은 경로 특정 moviesServerError.handlebars /movies 를 사용합니다 500
필요한 쿼리 매개 변수 actor 전달되지 않으면 Walder는 상태 코드 404 반환합니다. Config 파일에는 해당 상태에 대한 경로 별 HTML 뷰 템플릿이 없기 때문에 Walder는 기본 error404.html 파일을 사용합니다.
...
paths :
/movies :
get :
summary : Returns a list of the all movies the given actor stars in
parameters :
- in : query
name : actor
schema :
type : string
minimum : 0
description : The actor from whom the movies are requested
required : true
x-walder-query :
graphql-query : >
{
id @single
... on Film {
starring(label: $actor) @single
}
}
json-ld-context : >
{
"@context": {
"Film": "http://dbpedia.org/ontology/Film",
"label": { "@id": "http://www.w3.org/2000/01/rdf-schema#label", "@language": "en" },
"starring": "http://dbpedia.org/ontology/starring"
}
}
responses :
200 :
description : list of movies
x-walder-input-text/html : movies.pug
500 :
description : internal movie server error
x-walder-input-text/html : moviesServerError.handlebars
x-walder-errors :
404 :
description : page not found error
x-walder-input-text/html : error404.html
500 :
description : internal server error
x-walder-input-text/html : error500.html 웹 사이트를 개발하는 동안 config.yaml 변경하는 동안 웹 사이트를 다시로드하기를 원할 것입니다. NPM 시계를 사용하여 쉽게이 작업을 수행 할 수 있습니다. 시작 방법에 대해서는 아래의 package.json 스 니펫을 참조하십시오
{
"watch" : {
"run" : " config.yaml "
},
"scripts" : {
"run" : " walder -c config.yaml --no-cache " ,
"watch" : " npm-watch "
},
"dependencies" : {
"walder" : " ^2.0.1 "
},
"devDependencies" : {
"npm-watch" : " ^0.7.0 "
}
} npm run watch 실행하고 Walder는 모든 config.yaml 변경을 다시로드합니다!
| 도서관 | 특허 |
|---|---|
| @comunica | MIT |
| 수락합니다 | MIT |
| axios | MIT |
| 차이 | MIT |
| 사령관 | MIT |
| 통합하다 | MIT |
| 디버그 | MIT |
| 표현하다 | MIT |
| 전면 | MIT |
| fs-extra | MIT |
| 그래프 QL-LD | MIT |
| GraphQL-LD-Comunica | MIT |
| 핸들 바 | MIT |
| IS-HTML | MIT |
| jade-to-handlebars | MIT |
| JSON-Refs | MIT |
| JSONLD | BSD-3-Clause |
| JSONPATH | MIT |
| Markdown-it | MIT |
| 모카 | MIT |
| 모건 | MIT |
| n3 | MIT |
| 객체 경로 | MIT |
| 이긴 흙 | MIT |
| 수퍼 테스트 | MIT |
| TMP | MIT |
| 윈스턴 | MIT |
| 얌 | ISC |
Walder를 만들고 목록에 추가하고 싶었습니까? 풀 요청을 작성하십시오!
이 코드는 Ghent University - IMEC에 의해 저작권 © 2019–2020이며 MIT 라이센스에 따라 출시되었습니다.