Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: GQL responses #2872

Merged
merged 18 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
66 changes: 35 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,13 @@ Expected response:

```json
{
"data": [
{
"_docID": "bae-91171025-ed21-50e3-b0dc-e31bccdfa1ab",
}
]
"data": {
"create_User": [
{
"_docID": "bae-91171025-ed21-50e3-b0dc-e31bccdfa1ab",
}
]
}
}
```

Expand Down Expand Up @@ -223,37 +225,39 @@ It returns a structure similar to the following, which contains the update paylo

```json
{
"data": [
{
"cid": "bafybeifhtfs6vgu7cwbhkojneh7gghwwinh5xzmf7nqkqqdebw5rqino7u",
"delta": "pGNhZ2UYH2RuYW1lY0JvYmZwb2ludHMYWmh2ZXJpZmllZPU=",
"height": 1,
"links": [
{
"cid": "bafybeiet6foxcipesjurdqi4zpsgsiok5znqgw4oa5poef6qtiby5hlpzy",
"name": "age"
},
{
"cid": "bafybeielahxy3r3ulykwoi5qalvkluojta4jlg6eyxvt7lbon3yd6ignby",
"name": "name"
},
{
"cid": "bafybeia3tkpz52s3nx4uqadbm7t5tir6gagkvjkgipmxs2xcyzlkf4y4dm",
"name": "points"
},
{
"cid": "bafybeia4off4javopmxcdyvr6fgb5clo7m5bblxic5sqr2vd52s6khyksm",
"name": "verified"
}
]
}
]
"data": {
"latestCommits": [
{
"cid": "bafybeifhtfs6vgu7cwbhkojneh7gghwwinh5xzmf7nqkqqdebw5rqino7u",
"delta": "pGNhZ2UYH2RuYW1lY0JvYmZwb2ludHMYWmh2ZXJpZmllZPU=",
"height": 1,
"links": [
{
"cid": "bafybeiet6foxcipesjurdqi4zpsgsiok5znqgw4oa5poef6qtiby5hlpzy",
"name": "age"
},
{
"cid": "bafybeielahxy3r3ulykwoi5qalvkluojta4jlg6eyxvt7lbon3yd6ignby",
"name": "name"
},
{
"cid": "bafybeia3tkpz52s3nx4uqadbm7t5tir6gagkvjkgipmxs2xcyzlkf4y4dm",
"name": "points"
},
{
"cid": "bafybeia4off4javopmxcdyvr6fgb5clo7m5bblxic5sqr2vd52s6khyksm",
"name": "verified"
}
]
}
]
}
}
```

Obtain a specific commit by its content identifier (`cid`):

```gql
```shell
defradb client query '
query {
commits(cid: "bafybeifhtfs6vgu7cwbhkojneh7gghwwinh5xzmf7nqkqqdebw5rqino7u") {
Expand Down
52 changes: 27 additions & 25 deletions docs/website/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,31 +153,33 @@ It returns a structure similar to the following, which contains the update paylo

```json
{
"data": [
{
"cid": "bafybeifhtfs6vgu7cwbhkojneh7gghwwinh5xzmf7nqkqqdebw5rqino7u",
"delta": "pGNhZ2UYH2RuYW1lY0JvYmZwb2ludHMYWmh2ZXJpZmllZPU=",
"height": 1,
"links": [
{
"cid": "bafybeiet6foxcipesjurdqi4zpsgsiok5znqgw4oa5poef6qtiby5hlpzy",
"name": "age"
},
{
"cid": "bafybeielahxy3r3ulykwoi5qalvkluojta4jlg6eyxvt7lbon3yd6ignby",
"name": "name"
},
{
"cid": "bafybeia3tkpz52s3nx4uqadbm7t5tir6gagkvjkgipmxs2xcyzlkf4y4dm",
"name": "points"
},
{
"cid": "bafybeia4off4javopmxcdyvr6fgb5clo7m5bblxic5sqr2vd52s6khyksm",
"name": "verified"
}
]
}
]
"data": {
"latestCommits": [
{
"cid": "bafybeifhtfs6vgu7cwbhkojneh7gghwwinh5xzmf7nqkqqdebw5rqino7u",
"delta": "pGNhZ2UYH2RuYW1lY0JvYmZwb2ludHMYWmh2ZXJpZmllZPU=",
"height": 1,
"links": [
{
"cid": "bafybeiet6foxcipesjurdqi4zpsgsiok5znqgw4oa5poef6qtiby5hlpzy",
"name": "age"
},
{
"cid": "bafybeielahxy3r3ulykwoi5qalvkluojta4jlg6eyxvt7lbon3yd6ignby",
"name": "name"
},
{
"cid": "bafybeia3tkpz52s3nx4uqadbm7t5tir6gagkvjkgipmxs2xcyzlkf4y4dm",
"name": "points"
},
{
"cid": "bafybeia4off4javopmxcdyvr6fgb5clo7m5bblxic5sqr2vd52s6khyksm",
"name": "verified"
}
]
}
]
}
}
```

Expand Down
38 changes: 18 additions & 20 deletions docs/website/guides/explain-systems.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,26 +134,24 @@ query @explain(type: execute) {

```json
// Response
[
{
"explain": {
"executionSuccess": true,
"sizeOfResult": 1,
"planExecutions": 2,
"selectTopNode": {
"selectNode": {
"iterations": 2,
"filterMatches": 1,
"scanNode": {
"iterations": 2,
"docFetches": 2,
"filterMatches": 1
}
}
}
}
}
]
{
"explain": {
"executionSuccess": true,
"sizeOfResult": 1,
"planExecutions": 2,
"selectTopNode": {
"selectNode": {
"iterations": 2,
"filterMatches": 1,
"scanNode": {
"iterations": 2,
"docFetches": 2,
"filterMatches": 1
}
}
}
}
}
```

Because Execute Explain actually executes the plan, it will of course take more time to complete and return results than the Simple Explain. It will actually take slightly longer to execute than the non-explain counterpart, as it has the overhead of measuring and collecting information.
Expand Down
112 changes: 60 additions & 52 deletions docs/website/guides/schema-relationship.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,23 +234,25 @@ query {

```json
// Results:
[
{
"name": "Saadi Shirazi",
"dateOfBirth": "1210-07-23T03:46:56.647Z",
"authoredBooks": [
{
"name": "Gulistan",
"genre": "Poetry",
"description": "Persian poetry of ideas"
},
{
"name": "Bustan",
"genre": "Poetry"
}
]
}
]
{
"Author": [
{
"name": "Saadi Shirazi",
"dateOfBirth": "1210-07-23T03:46:56.647Z",
"authoredBooks": [
{
"name": "Gulistan",
"genre": "Poetry",
"description": "Persian poetry of ideas"
},
{
"name": "Bustan",
"genre": "Poetry"
}
]
}
]
}
```

```graphql
Expand All @@ -268,24 +270,26 @@ query {

```json
// Results:
[
{
"name": "Gulistan",
"genre": "Poetry",
"Author": {
"name": "Saadi Shirazi",
"dateOfBirth": "1210-07-23T03:46:56.647Z",
}
},
{
"name": "Bustan",
"genre": "Poetry",
"Author": {
"name": "Saadi Shirazi",
"dateOfBirth": "1210-07-23T03:46:56.647Z",
{
"Book": [
{
"name": "Gulistan",
"genre": "Poetry",
"Author": {
"name": "Saadi Shirazi",
"dateOfBirth": "1210-07-23T03:46:56.647Z",
}
},
{
"name": "Bustan",
"genre": "Poetry",
"Author": {
"name": "Saadi Shirazi",
"dateOfBirth": "1210-07-23T03:46:56.647Z",
}
}
}
]
]
}
```

```graphql
Expand All @@ -303,18 +307,20 @@ query {

```json
// Results:
[
{
"name": "Saadi Shirazi",
"dateOfBirth": "1210-07-23T03:46:56.647Z",
"authoredBooks": [
{
"name": "Gulistan",
"genre": "Poetry"
}
]
}
]
{
"Author": [
{
"name": "Saadi Shirazi",
"dateOfBirth": "1210-07-23T03:46:56.647Z",
"authoredBooks": [
{
"name": "Gulistan",
"genre": "Poetry"
}
]
}
]
}
```

```graphql
Expand All @@ -330,12 +336,14 @@ query {

```json
// Results:
[
{
"name": "Saadi Shirazi",
"dateOfBirth": "1210-07-23T03:46:56.647Z"
}
]
{
"Author": [
{
"name": "Saadi Shirazi",
"dateOfBirth": "1210-07-23T03:46:56.647Z"
}
]
}
```

Note:
Expand Down
4 changes: 2 additions & 2 deletions http/handler_ccip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func TestCCIPGet_WithValidData(t *testing.T) {
resHex, err := hex.DecodeString(strings.TrimPrefix(ccipRes.Data, "0x"))
require.NoError(t, err)

assert.JSONEq(t, `{"data": [{"name": "bob"}]}`, string(resHex))
assert.JSONEq(t, `{"data": {"User": [{"name": "bob"}]}}`, string(resHex))
}

func TestCCIPGet_WithSubscription(t *testing.T) {
Expand Down Expand Up @@ -153,7 +153,7 @@ func TestCCIPPost_WithValidData(t *testing.T) {
resHex, err := hex.DecodeString(strings.TrimPrefix(ccipRes.Data, "0x"))
require.NoError(t, err)

assert.JSONEq(t, `{"data": [{"name": "bob"}]}`, string(resHex))
assert.JSONEq(t, `{"data": {"User": [{"name": "bob"}]}}`, string(resHex))
}

func TestCCIPPost_WithInvalidGraphQLRequest(t *testing.T) {
Expand Down
15 changes: 1 addition & 14 deletions http/handler_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ func (res *GraphQLResponse) UnmarshalJSON(data []byte) error {
if err := dec.Decode(&out); err != nil {
return err
}
res.Data = out["data"]

// fix errors type to match tests
switch t := out["errors"].(type) {
Expand All @@ -278,20 +279,6 @@ func (res *GraphQLResponse) UnmarshalJSON(data []byte) error {
res.Errors = nil
}

// fix data type to match tests
switch t := out["data"].(type) {
case []any:
var fixed []map[string]any
for _, v := range t {
fixed = append(fixed, v.(map[string]any))
}
res.Data = fixed
case map[string]any:
res.Data = t
default:
res.Data = []map[string]any{}
}

return nil
}

Expand Down
10 changes: 1 addition & 9 deletions internal/db/collection_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,15 +259,7 @@ func (c *collection) makeSelectionPlan(
txn,
)

return planner.MakePlan(&request.Request{
Queries: []*request.OperationDefinition{
{
Selections: []request.Selection{
slct,
},
},
},
})
return planner.MakeSelectionPlan(slct)
}

func (c *collection) makeSelectLocal(filter immutable.Option[request.Filter]) (*request.Select, error) {
Expand Down
Loading
Loading