Skip to content

Commit

Permalink
Fix #1477 and #1464
Browse files Browse the repository at this point in the history
  • Loading branch information
Pawan Rawal committed Sep 18, 2017
1 parent d47f51b commit 27d2467
Show file tree
Hide file tree
Showing 14 changed files with 173 additions and 158 deletions.
3 changes: 3 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,9 @@ func (e *Edge) setValueString(val string) error {
return err
}

if len(val) == 0 {
val = "_nil_"
}
v, err := types.ObjectValue(types.StringID, val)
if err != nil {
return err
Expand Down
16 changes: 16 additions & 0 deletions client_test/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,3 +317,19 @@ func TestLangTag(t *testing.T) {
require.Equal(t, 1, len(r2.Root))
require.Equal(t, "Алиса", r2.Root[0].Name)
}

func TestEmptyString(t *testing.T) {
dirs, options := prepare()
defer removeDirs(dirs)

dgraphClient := dgraph.NewEmbeddedDgraphClient(options, client.DefaultOptions, dirs[0])
defer dgraph.DisposeEmbeddedDgraph()
req := client.Req{}
alice, err := dgraphClient.NodeBlank("")
require.NoError(t, err)
e := alice.Edge("name")
require.NoError(t, e.SetValueString(""))
require.NoError(t, req.Set(e))
_, err = dgraphClient.Run(context.Background(), &req)
require.NoError(t, err)
}
4 changes: 2 additions & 2 deletions dashboard/build/asset-manifest.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"main.css": "static/css/main.563fd548.css",
"main.css.map": "static/css/main.563fd548.css.map",
"main.js": "static/js/main.1b4f298d.js",
"main.js.map": "static/js/main.1b4f298d.js.map",
"main.js": "static/js/main.093ffb81.js",
"main.js.map": "static/js/main.093ffb81.js.map",
"static/media/addNodeIcon.png": "static/media/addNodeIcon.a1a2d01b.png",
"static/media/backIcon.png": "static/media/backIcon.dd0baa69.png",
"static/media/connectIcon.png": "static/media/connectIcon.d5267b8d.png",
Expand Down
2 changes: 1 addition & 1 deletion dashboard/build/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="shortcut icon" href="/favicon.ico"><script>window.SERVER_URL=location.protocol+"//"+location.hostname+(location.port?":"+location.port:"")</script><script src="https://use.fontawesome.com/bd4789f5b8.js"></script><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.25.2/theme/neo.css" integrity="sha256-qRnm2qfT/Q52+7DC2rgmj2+ZjTgb9s12gC6tuLb0tv0=" crossorigin="anonymous"/><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.11.0/styles/github.min.css" integrity="sha256-3YM6A3pH4QFCl9WbSU8oXF5N6W/2ylvW0o2g+Z6TmLQ=" crossorigin="anonymous"/><title>Dgraph Browser</title><script>!function(e,t,r,n,a){if(!e[a]){for(var i=e[a]=[],s=0;s<r.length;s++){var c=r[s];i[c]=i[c]||function(e){return function(){var t=Array.prototype.slice.call(arguments);i.push([e,t])}}(c)}i.SNIPPET_VERSION="1.0.1";var o=t.createElement("script");o.type="text/javascript",o.async=!0,o.src="https://d2yyd1h5u9mauk.cloudfront.net/integrations/web/v1/library/NKLggFBPuCtnmits/"+a+".js";var u=t.getElementsByTagName("script")[0];u.parentNode.insertBefore(o,u)}}(window,document,["survey","reset","config","init","set","get","event","identify","track","page","screen","group","alias"],0,"delighted")</script><link href="/static/css/main.563fd548.css" rel="stylesheet"></head><body><div id="root"></div><script>!function(){var e,t,r=document,c=r.getElementById,m=r.createElement,a=r.getElementsByTagName,l="typef_orm_share";c.call(r,l)||(e=m.call(r,"script"),e.id=l,e.src="https://embed.typeform.com/embed.js",t=a.call(r,"script")[0],t.parentNode.insertBefore(e,t))}()</script><script type="text/javascript" src="/static/js/main.1b4f298d.js"></script></body></html>
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="shortcut icon" href="/favicon.ico"><script>window.SERVER_URL=location.protocol+"//"+location.hostname+(location.port?":"+location.port:"")</script><script src="https://use.fontawesome.com/bd4789f5b8.js"></script><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.25.2/theme/neo.css" integrity="sha256-qRnm2qfT/Q52+7DC2rgmj2+ZjTgb9s12gC6tuLb0tv0=" crossorigin="anonymous"/><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.11.0/styles/github.min.css" integrity="sha256-3YM6A3pH4QFCl9WbSU8oXF5N6W/2ylvW0o2g+Z6TmLQ=" crossorigin="anonymous"/><title>Dgraph Browser</title><script>!function(e,t,r,n,a){if(!e[a]){for(var i=e[a]=[],s=0;s<r.length;s++){var c=r[s];i[c]=i[c]||function(e){return function(){var t=Array.prototype.slice.call(arguments);i.push([e,t])}}(c)}i.SNIPPET_VERSION="1.0.1";var o=t.createElement("script");o.type="text/javascript",o.async=!0,o.src="https://d2yyd1h5u9mauk.cloudfront.net/integrations/web/v1/library/NKLggFBPuCtnmits/"+a+".js";var u=t.getElementsByTagName("script")[0];u.parentNode.insertBefore(o,u)}}(window,document,["survey","reset","config","init","set","get","event","identify","track","page","screen","group","alias"],0,"delighted")</script><link href="/static/css/main.563fd548.css" rel="stylesheet"></head><body><div id="root"></div><script>!function(){var e,t,r=document,c=r.getElementById,m=r.createElement,a=r.getElementsByTagName,l="typef_orm_share";c.call(r,l)||(e=m.call(r,"script"),e.id=l,e.src="https://embed.typeform.com/embed.js",t=a.call(r,"script")[0],t.parentNode.insertBefore(e,t))}()</script><script type="text/javascript" src="/static/js/main.093ffb81.js"></script></body></html>
55 changes: 55 additions & 0 deletions dashboard/build/static/js/main.093ffb81.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

55 changes: 0 additions & 55 deletions dashboard/build/static/js/main.1b4f298d.js

This file was deleted.

19 changes: 8 additions & 11 deletions dashboard/src/actions/connection.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const UPDATE_CONNECTED_STATE = "connection/UPDATE_CONNECTED_STATE";

import { timeout, getEndpoint } from "../lib/helpers";
import { getEndpoint } from "../lib/helpers";

export function updateConnectedState(nextState) {
return {
Expand All @@ -15,16 +15,13 @@ export function updateConnectedState(nextState) {
*/
export function refreshConnectedState() {
return dispatch => {
return timeout(
6000,
fetch(getEndpoint("health"), {
method: "GET",
mode: "cors",
headers: {
Accept: "application/json"
}
})
)
return fetch(getEndpoint("health"), {
method: "GET",
mode: "cors",
headers: {
Accept: "application/json"
}
})
.then(response => {
let nextConnectedState;
if (response.status === 200) {
Expand Down
47 changes: 22 additions & 25 deletions dashboard/src/components/FrameItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,32 +49,22 @@ class FrameItem extends React.Component {
};

getAndExecuteSharedQuery = shareId => {
return getSharedQuery(shareId)
.then(query => {
if (!query) {
this.setState({
errorMessage: `No query found for the shareId: ${shareId}`,
executed: true
});
} else {
this.executeFrameQuery(query);
const { frame, updateFrame } = this.props;
updateFrame({
query: query,
id: frame.id,
// Lets update share back to empty, because we now have the query.
share: ""
})();
}
})
.catch(error => {
Raven.captureException(error);
this.setState({
executed: true,
data: error,
errorMessage: error.message
});
let query = getSharedQuery(shareId);
if (!query) {
this.setState({
errorMessage: `No query found for the shareId: ${shareId}`,
executed: true
});
} else {
this.executeFrameQuery(query);
const { frame, updateFrame } = this.props;
updateFrame({
query: query,
id: frame.id,
// Lets update share back to empty, because we now have the query.
share: ""
})();
}
};

executeOnJsonClick = () => {
Expand Down Expand Up @@ -144,6 +134,13 @@ class FrameItem extends React.Component {
};

this.setState({ response, executed: true });
let hasMutation = query.indexOf("mutation") > -1;
if (hasMutation) {
// This would mean that its not run again when user clicks on JSON tab.
// TODO - Ideally, we want to remove the mutation and run the query again.
// Maybe parse the query and remove the mutation block.
this.setState({ response, data: res });
}
} else {
this.setState({
successMessage: "Your query did not return any results",
Expand Down
75 changes: 33 additions & 42 deletions dashboard/src/containers/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@ import React, { Component } from "react";
import { connect } from "react-redux";
import _ from "lodash";

import {
timeout,
checkStatus,
sortStrings,
getEndpointBaseURL
} from "../lib/helpers";
import { checkStatus, sortStrings, getEndpointBaseURL } from "../lib/helpers";
import "../assets/css/Editor.css";

require("codemirror/addon/hint/show-hint.css");
Expand Down Expand Up @@ -54,22 +49,19 @@ class Editor extends Component {
require("codemirror-graphql/mode");

let keywords = [];
timeout(
1000,
fetch(getEndpointBaseURL() + "/ui/keywords", {
method: "GET",
mode: "cors"
fetch(getEndpointBaseURL() + "/ui/keywords", {
method: "GET",
mode: "cors"
})
.then(checkStatus)
.then(response => response.json())
.then(function(result) {
keywords = keywords.concat(
result.keywords.map(kw => {
return kw.name;
})
);
})
.then(checkStatus)
.then(response => response.json())
.then(function(result) {
keywords = keywords.concat(
result.keywords.map(kw => {
return kw.name;
})
);
})
)
.catch(function(error) {
console.log(error.stack);
console.warn(
Expand All @@ -87,26 +79,23 @@ class Editor extends Component {
}
});

timeout(
1000,
fetch(getEndpointBaseURL() + "/query", {
method: "POST",
mode: "cors",
body: "schema {}"
fetch(getEndpointBaseURL() + "/query", {
method: "POST",
mode: "cors",
body: "schema {}"
})
.then(checkStatus)
.then(response => response.json())
.then(function(result) {
var data = result.data;
if (data.schema && !_.isEmpty(data.schema)) {
keywords = keywords.concat(
data.schema.map(kw => {
return kw.predicate;
})
);
}
})
.then(checkStatus)
.then(response => response.json())
.then(function(result) {
var data = result.data;
if (data.schema && !_.isEmpty(data.schema)) {
keywords = keywords.concat(
data.schema.map(kw => {
return kw.predicate;
})
);
}
})
)
.catch(function(error) {
console.log(error.stack);
console.warn("In catch: Error while trying to fetch schema", error);
Expand Down Expand Up @@ -151,10 +140,12 @@ class Editor extends Component {
this.editor.setCursor(this.editor.lineCount(), 0);

CodeMirror.registerHelper("hint", "fromList", function(cm, options) {
var cur = cm.getCursor(), token = cm.getTokenAt(cur);
var cur = cm.getCursor(),
token = cm.getTokenAt(cur);

var to = CodeMirror.Pos(cur.line, token.end);
let from = "", term = "";
let from = "",
term = "";
if (token.string) {
term = token.string;
from = CodeMirror.Pos(cur.line, token.start);
Expand Down
28 changes: 8 additions & 20 deletions dashboard/src/lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,6 @@ export function checkStatus(response) {
}
}

export function timeout(ms, promise) {
return new Promise(function(resolve, reject) {
setTimeout(function() {
reject(new Error("timeout"));
}, ms);
promise.then(resolve, reject);
});
}

// outgoingEdges gets edges coming out from the node with the given nodeId in
// given set of edges
export function outgoingEdges(nodeId, edgeSet) {
Expand Down Expand Up @@ -221,21 +212,18 @@ export function executeQuery(query, debug) {
*
*/
export const getSharedQuery = shareId => {
return timeout(
6000,
fetch(getEndpoint("query"), {
method: "POST",
mode: "cors",
headers: {
Accept: "application/json"
},
body: `{
fetch(getEndpoint("query"), {
method: "POST",
mode: "cors",
headers: {
Accept: "application/json"
},
body: `{
query(func: uid(${shareId})) {
_share_
}
}`
})
)
})
.then(checkStatus)
.then(response => response.json())
.then(function(result) {
Expand Down
7 changes: 7 additions & 0 deletions gql/mutation.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ func typeValFrom(val *protos.Value) types.Val {
case *protos.Value_IntVal:
return types.Val{types.IntID, val.GetIntVal()}
case *protos.Value_StrVal:
if val.GetStrVal() == "" {
return types.Val{types.StringID, "_nil_"}
}
return types.Val{types.StringID, val.GetStrVal()}
case *protos.Value_BoolVal:
return types.Val{types.BoolID, val.GetBoolVal()}
Expand All @@ -175,8 +178,12 @@ func typeValFrom(val *protos.Value) types.Val {
case *protos.Value_PasswordVal:
return types.Val{types.PasswordID, val.GetPasswordVal()}
case *protos.Value_DefaultVal:
if val.GetDefaultVal() == "" {
return types.Val{types.DefaultID, "_nil_"}
}
return types.Val{types.DefaultID, val.GetDefaultVal()}
}

return types.Val{types.StringID, ""}
}

Expand Down
3 changes: 2 additions & 1 deletion gql/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -2468,7 +2468,8 @@ func godeep(it *lex.ItemIterator, gq *GraphQuery) error {
MathExp: mathTree,
IsInternal: true,
}
varName = ""
// TODO - See that if we can instead initialize this at the top.
varName, alias = "", ""
gq.Children = append(gq.Children, child)
curp = nil
continue
Expand Down
15 changes: 15 additions & 0 deletions query/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9360,3 +9360,18 @@ func TestFilterRoot(t *testing.T) {
js := processToFastJSON(t, query)
require.JSONEq(t, `{"data": {}}`, js)
}

func TestMathAlias(t *testing.T) {
populateGraph(t)

query := `{
me(func:allofterms(name, "Michonne")) {
p as count(friend)
score: math(p + 1)
name
}
}`

js := processToFastJSON(t, query)
require.JSONEq(t, `{"data": {"me":[{"count(friend)":5,"score":6.000000,"name":"Michonne"}]}}`, js)
}

0 comments on commit 27d2467

Please sign in to comment.