小编Kai*_* Li的帖子

类型错误:字符串不能代表值:graphql 查询不起作用

我正在尝试运行 graphql 查询,但它一直给我“类型错误:字符串不能代表值:”错误。

我的查询的架构:

    type User {
        active: Boolean!
        email: String!
        fullname: String!
        description: String!
        tags: [String!]!
    }

    type Query {
        getAllUsers: [User]!
    }
Run Code Online (Sandbox Code Playgroud)

我的解析器:

Query: {
        getAllUsers: (_, __, { dataSources }) => {
            return dataSources.userAPI.getAllUsers();
        }
    }
Run Code Online (Sandbox Code Playgroud)

用户API:

    type User {
        active: Boolean!
        email: String!
        fullname: String!
        description: String!
        tags: [String!]!
    }

    type Query {
        getAllUsers: [User]!
    }
Run Code Online (Sandbox Code Playgroud)

查询:

query getAllUsers{
  getAllUsers{
    email
  }
}
Run Code Online (Sandbox Code Playgroud)

由于我的电子邮件是一个字符串,我得到的错误是“字符串不能代表值”。

node.js apollo graphql

6
推荐指数
1
解决办法
1万
查看次数

jQuery 按键输入不起作用

我尝试使用按键来获取文本以更新 中的文本。我的 html 看起来像这样:

<p>words words words <i>test</i> more words</p>
<div id="newWord">
   <form>
      <input type="text" placeholder="New Hashtag"></input>
   </form>
</div>
Run Code Online (Sandbox Code Playgroud)

我的 jQuery 看起来像这样:

$(document).ready(function () {
    $("input").keypress(
        function (e) {
            var currentInput = $("input").val();
            console.log(currentInput);
            if (e.keyCode === 13) {
                console.log('hello');
            }
        }
    );
})
Run Code Online (Sandbox Code Playgroud)

我的控制台日志未在第一次按键时记录,我该如何解决?我的“你好”也从不记录。有什么想法为什么会发生这种情况吗?

谢谢!

html javascript jquery input keypress

3
推荐指数
1
解决办法
1万
查看次数

为什么If语句为hashTable返回undefined?

有人能解释这个JavaScript的怪癖吗?

一个例子:

function func(hashTable) {
  if (hashTable['foo'])
    return true;
}

var hash = {};
hash['foo'] = 0;
func(hash);
Run Code Online (Sandbox Code Playgroud)

我得到undefined而不是true.

javascript algorithm hashtable data-structures

2
推荐指数
1
解决办法
146
查看次数

JavaScript返回没有返回

我写了一个简单的函数来检查一个数组是否包含重复项,我希望它返回true,否则返回true.

function containsDuplicates(a) {
    var hash = {};
    a.forEach((elem, index) => {
        if (hash[elem] === undefined) {
            hash[elem] = 1;
        } else {
            console.log('true')
            return true;
        }

        if (index === a.length - 1) {
            console.log('false')
            return false;
        }
    })
}

var arr = [1, 2, 3, 4];
containsDuplicates(arr)
Run Code Online (Sandbox Code Playgroud)

我的console.log日志很好,但它似乎没有达到回报.我的整个函数每次都返回undefined.为什么会这样?

javascript

2
推荐指数
1
解决办法
70
查看次数