小编Hen*_*Jan的帖子

Graphql 将多个查询合并(组合)为一个?

我正在尝试使用 JavaScript 将多个 Graphql 查询合并为一个查询。
我正在寻找这样的东西:

let query3 = mergeQueries(query1, query2);
Run Code Online (Sandbox Code Playgroud)

我们事先不知道将合并哪些查询。

假设我有这样的查询:

输入查询1:

{
  post(id: 1234) {
    title
    description
  }
}
Run Code Online (Sandbox Code Playgroud)

输入查询2:

{
  post(id: 1234) {
    tags
    author {
      name
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

然后我希望结果 query3 为:
result query3:

{
  post(id: 1234) {
    title
    tags
    description
    author {
      name
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

这与 lodash_.merge()为 JSON 对象所做的功能相同,但随后使用 Graphql 查询而不是 JSON 对象。

javascript graphql

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

Vuetify 数据表行中的计算属性

我正在为网站使用 Vuetify 和 Vuetify/Datatables。现在我想要computed表格的每一行都有一些属性。

为此,我可能需要制作<template>元素的一个组件并向该组件添加计算属性。我试过了,<template is="myComponent" :m="props.item">但这没有用。

<v-data-table
  :headers="headers"
  :items="items"
  hide-actions
  class="elevation-1"
>
  <template slot="items" slot-scope="props">
    <td>{{ THIS_VALUE_COMPUTED }}</td>
    <td class="text-xs-right">{{ props.item.calories }}</td>
    <td class="text-xs-right">{{ props.item.fat }}</td>
    <td class="text-xs-right">{{ props.item.carbs }}</td>
    <td class="text-xs-right">{{ props.item.protein }}</td>
    <td class="text-xs-right">{{ props.item.iron }}</td>
  </template>
</v-data-table>
Run Code Online (Sandbox Code Playgroud)

computed-properties vue-component vuetify.js

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

如何使用 Typescript 在 Vue 3.0 setup() 函数中使用 async/await

(此问题已针对 JavaScript 回答,见下文,但此问题特定于 TypeScript,其行为不同)

我正在尝试使用打字稿在 Vue3.0 中使用异步功能。

没有异步,这段代码很好用:

// file: components/HelloWorld.vue

<template>
  <div class="hello">
    <h1>{{ msg }}</h1>
  </div>
</template>

<script lang="ts">
import {defineComponent} from 'vue'

export default defineComponent({
  name: 'HelloWorld',
  props: {
    msg: String,
  },
  async setup() { // <-- this works without 'async'
    const test = 'test'

    // await doSomethingAsynchronous()

    return {
      test,
    }
  },
})
</script>
Run Code Online (Sandbox Code Playgroud)

随着async setup()组件“HelloWorld”从页面中消失,Firefox 控制台告诉我

"Uncaught (in promise) TypeError: node is null (runtime-dom.esm-bundler.js)"
Run Code Online (Sandbox Code Playgroud)

当我更改async setup()为 时setup(),代码有效,但随后我将无法在 …

async-await typescript vue.js vuejs3 vue-composition-api

8
推荐指数
3
解决办法
8682
查看次数

Vue 3,“无法解析组件”错误的原因是什么?

我试图将一个组件包含到另一个组件中,但在浏览器控制台中收到错误“无法解析组件:应用程序概述表”。

父组件“src/pages/ApplicationsOverview.vue”:

<template>
  <q-page class="flex flex-center">
    <applications-overview-table></applications-overview-table>
  </q-page>
</template>

<script>
import ApplicationsOverviewTable from '../components/application/OverviewTable.vue';

export default {
  name: 'ApplicationsOverviewPage',

  components: [ApplicationsOverviewTable],

  setup() {
    console.log('loading applications overview');

    return {};
  },
};
</script>

<style></style>
Run Code Online (Sandbox Code Playgroud)

子组件“src/applications/OverviewTable.vue”:

<template>
  <div class="q-pa-md">
    <q-table title="Aanvragen" :rows="rows" :columns="columns" row-key="name" />
  </div>
</template>

<script>
const columns = [ ... ];
const rows = [ ... ];

export default {
  name: 'ApplicationsOverviewTable',
  setup() {
    return {
      columns,
      rows,
    };
  },
};
</script>

Run Code Online (Sandbox Code Playgroud)

我可以看到正在加载父组件,因为控制台中显示了控制台消息“正在加载应用程序概述”。
我还可以看到路径OverviewTable.vue是正确的,因为如果我更改路径,则会出现另一个错误。

我尝试更改<applications-overview-table>为,<ApplicationsOverviewTable> …

vue.js vue-component vuejs3 vue-composition-api vue-sfc

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

Dart相当于Array.prototype.map()?

我尝试从Dart中的地图列表中获取id. 在JavaScript中它将是这样的:

var list = [{id:3, name:'third'}, {id:4, name:'fourth'}];
var result = list.map(function(x){return x.id;});
Run Code Online (Sandbox Code Playgroud)

这应该给出结果

[3, 4]
Run Code Online (Sandbox Code Playgroud)

在Dart有一个简单的方法吗?


到目前为止,我能够做到这一点(在Dart中):

var list = [{'id':3, 'name':'third'},{'id':4, 'name':'fourth'}];
var result = list.map((x) => x['id']);
Run Code Online (Sandbox Code Playgroud)

结果是"MappedListIterable"(不确定是什么),你不能result[0]像普通List那样使用.我怎样才能列出这个?

javascript arrays dart

7
推荐指数
1
解决办法
399
查看次数

火箭没有设置内容类型的文本/ html

我正在使用Rust Rocket框架生成一个简单的网页.

当去索引页面"/"时:

#[get("/")]
fn page_index() -> &'static str {
    r#"
        <title>GCD Calculator</title>
        <form action="/gcd" method="post">
            <input type="text" name="n" />
            <input type="text" name="n" />
            <button type="submit">Compute GCD</button>
        </form>
    "#
}
Run Code Online (Sandbox Code Playgroud)

服务器控制台告诉我

GET / text/html:
=> Matched: GET /
=> Outcome: Success
=> Response succeeded.
Run Code Online (Sandbox Code Playgroud)

但是我的浏览器告诉我Content-Type是text/plain.

如何使Rocket正确响应text/html.我做错了什么还是Rocket?

content-type rust

7
推荐指数
2
解决办法
557
查看次数

如何在 Vue-cli 中配置 Webpack?

编辑:我停止尝试让它工作。


我正在使用 Vue-cli ( https://github.com/chrisvfritz/vue-enterprise-boilerplate ),它在水下使用 Webpack 创建网站。

现在我想更改我的webpack.config.js但是这个文件不存在。

vue.config.js包含一个configureWebpack属性,但这似乎与普通 Webpack 配置的格式不同。

我想使用的 Webpack 配置是这样的:

// Webpack config
const webpack = require('webpack');
const path = require('path');
const nodeExternals = require('webpack-node-externals');
const StartServerPlugin = require('start-server-webpack-plugin');

module.exports = {
    entry: ['webpack/hot/poll?1000', './src/index'],
    watch: true,
    target: 'node',
    node: {
        __filename: true,
        __dirname: true
    },
    externals: [nodeExternals({ whitelist: ['webpack/hot/poll?1000'] })],
    module: {
        rules: [
            ...
        ]
    },
    plugins: [
        new StartServerPlugin('server.js'),
        new webpack.NamedModulesPlugin(),
        new webpack.HotModuleReplacementPlugin(),
        new webpack.NoEmitOnErrorsPlugin(),
        new webpack.DefinePlugin({ …
Run Code Online (Sandbox Code Playgroud)

javascript webpack vue.js vue-cli

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

Laravel phpunit 如何使用不同的迁移进行测试

我正在尝试在 Laravel 中设置测试,但我想运行与通常运行的迁移不同的迁移。

我运行的用于启动数据库的迁移从生产环境导入数据。
为了进行测试,我想使用一个名为“test”的不同数据库,并且我想用测试数据而不是生产数据填充此测试数据库。

我添加了一个config/database.php使用“测试”数据库的“测试”连接:

'connections' => [

        'mysql' => [
            'database' => env('DB_DATABASE', 'forge'),
            ...
        ],

        'testing' => [
            'database' => 'test',
            ...
        ],
],
Run Code Online (Sandbox Code Playgroud)

我设置phpunit.xml使用这个“测试”连接:

<?xml version="1.0" encoding="UTF-8"?>
<phpunit ...>
    ...
    <php>
        <env name="DB_CONNECTION" value="testing"/>
        ...
    </php>
</phpunit>
Run Code Online (Sandbox Code Playgroud)

现在我想使用测试数据初始化这个“测试”数据库,使用来自与默认文件夹不同的文件夹的迁移。

我可以像这样使用正常的迁移:

<?php

namespace Tests;

use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
use Illuminate\Foundation\Testing\DatabaseMigrations;

abstract class TestCase extends BaseTestCase
{
    use DatabaseMigrations;

    public function setUp(): void
    {
        parent::setUp();
        $this->seed();
    }
}
Run Code Online (Sandbox Code Playgroud)

但这使用默认文件夹database/migrations。我想将测试迁移放在文件夹中tests/database/migrations。

有没有办法让use …

php phpunit database-migration laravel

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

Vue 3 如何在响应式对象上使用 watch 或 watchEffect (和 console.log)?

我试图(深入)观察 Vue 3 中响应式对象的任何变化:

\n
import { reactive, watchEffect } from \'vue\';\n\nconst settings = reactive({\n  panes: {\n    left: {\n      defaultAction: "openInOtherPane",\n    },\n    right: {\n      defaultAction: "openInThisPane",\n    },\n  },\n  showMenu: false,\n  isDrawerOpen: false,\n});\n\nwatchEffect(() => {\n  console.log(\'The new settings are\', settings);\n});\n\n// Try to change a setting (this does not trigger watchEffect)\nsettings.panes.left.defaultAction = "none";\n
Run Code Online (Sandbox Code Playgroud)\n

这段代码有两个问题:

\n
    \n
  • 设置更改时不会触发 watchEffect
  • \n
  • console.log 以以下形式显示不可读的对象Proxy { <target>: {\xe2\x80\xa6}, <handler>: {\xe2\x80\xa6} }
  • \n
\n

我也尝试过watch:

\n
watch(\n  () => settings,\n  settings => {\n …
Run Code Online (Sandbox Code Playgroud)

javascript watch vue-reactivity vuejs3 vue-composition-api

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

Typescript:确保所有属性使用相同的元组类型

我有一个具有泛型的函数,它是 1 个元素的元组或 2 个元素的元组。
我想确保函数中使用的所有属性都使用相同长度的元组。

type TypeA = [string] // Tuple of 1 element
type TypeB = [string, string] // Tuple of 2 elements
type Header = TypeA | TypeB

interface SomeObject<H extends Header> {
    prop1: H
    prop2: H
}

function useHeader<H extends Header>(someObject:SomeObject<H>) {
    // do something
}

useHeader({
    prop1: ["tuple of 1 element"],
    prop2: [
        "tuple of", 
        "2 elements"
    ] // <-- I want an error here, because prop1 and prop2 use diffrent tuples
})
Run Code Online (Sandbox Code Playgroud)

我注意到,当我更改TypeA …

tuples type-safety typescript typescript-generics

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