- apollo というライブラリで、GraphQLのサーバを構築することができます。
- express 用のライブラリ(apollo-server-express)を利用しました。
- neo4jのアクセス(cypherとのつなぎ)は、neo4j-graphql-js。
- express の apps.js で実装です。
- GraphQLによるグラフDBのアクセス例
- 参照 (all gunclocks)
・ノードを全取得
{
Gunclock {
_id,
uuid,
size,
color
}
}
|
- 結果
{
"data": {
"Gunclock": [
{
"_id": "2",
"uuid": "6e854d99-57ca-4d78-bda2-80ea1e15721f",
"size": 22,
"color": "#cc88cc"
},
{
"_id": "40",
"uuid": "b786af21-fd75-470f-b3f3-f8f3022f6450",
"size": 25,
"color": "#88ffff"
},
{
"_id": "61",
"uuid": "c52af318-c351-4e89-99c0-da8cad143898",
"size": 16,
"color": "#ffff88"
},
{
"_id": "62",
"uuid": "5112845b-a3e6-415c-953a-afae40096e7d",
"size": 77,
"color": "#ff0000"
}
]
}
}
|
・ノードを全取得(リレーションも含めて全取得)
{
Gunclock {
_id,
uuid,
size,
color,
city{name},
shortHandCast{text},
longHandCast{text}
}
}
|
- 結果
{
"data": {
"Gunclock": [
{
"_id": "2",
"uuid": "6e854d99-57ca-4d78-bda2-80ea1e15721f",
"size": 22,
"color": "#cc88cc",
"city": {
"name": "Tokyo"
},
"shortHandCast": {
"text": [
"** __ *",
" _|__|_",
"b (@@) ",
" V|~~|>",
"* //T| "
]
},
"longHandCast": {
"text": [
"__AA **",
"| 6 |__P",
"~~| l",
"*/_/~l_l"
]
}
},
{
"_id": "40",
"uuid": "b786af21-fd75-470f-b3f3-f8f3022f6450",
"size": 25,
"color": "#88ffff",
"city": {
"name": "Sydney"
},
"shortHandCast": {
"text": [
"** __ *",
" _|__|_",
" (xx; ",
" /|~~|>",
"P //T| "
]
},
"longHandCast": {
"text": [
"/| A_A ",
"|||-.-| ",
"||_|-/_ ",
"||. ~. |"
]
}
},
{
"_id": "61",
"uuid": "c52af318-c351-4e89-99c0-da8cad143898",
"size": 16,
"color": "#ffff88",
"city": {
"name": "NewYork"
},
"shortHandCast": {
"text": [
"__AA **",
"| 6 |__P",
"~~| l",
"*/_/~l_l"
]
},
"longHandCast": {
"text": [
"/| A_A ",
"|||-.-| ",
"||_|-/_ ",
"||. ~. |"
]
}
},
{
"_id": "62",
"uuid": "5112845b-a3e6-415c-953a-afae40096e7d",
"size": 27,
"color": "#ff0000",
"city": {
"name": "Paris"
},
"shortHandCast": {
"text": [
"** __ *",
" _|__|_",
" (xx; ",
" /|~~|>",
"P //T| "
]
},
"longHandCast": {
"text": [
"** __ *",
" _|__|_",
"b (@@) ",
" V|~~|>",
"* //T| "
]
}
}
]
}
}
|
- 参照 (レコード指定(uuid検索))
{
Gunclock(
uuid:"c52af318-c351-4e89-99c0-da8cad143898"
)
{
_id,
uuid,
size,
color,
city{name},
shortHandCast{text},
longHandCast{text}
}
}
|
- 生成
mutation {
createGunclock(
size:16,
color:"0xffff88",
cityName:"Tokyo",
shortHandCastName:"gunman",
longHandCastName:"uma"
)
{
_id,
uuid,
size,
color,
city{name},
shortHandCast{text},
longHandCast{text}
}
}
|
- 更新 (レコード指定(uuid検索))
mutation {
updateGunclock(
uuid:"c52af318-c351-4e89-99c0-da8cad143898"
size:25,
color:"0x88ffcc",
cityName:"London",
shortHandCastName:"oni",
longHandCastName:"gunman2"
)
{
_id,
uuid,
size,
color,
city{name},
shortHandCast{text},
longHandCast{text}
}
}
|
- 削除 (レコード指定(uuid検索))
mutation {
deleteGunclock(
uuid:"c52af318-c351-4e89-99c0-da8cad143898"
)
{ _id }
}
|
|