小编Era*_*han的帖子

在 NestJS 中使用与 GraphQL 中的 Input 和 Object 类型相同的类

我正在尝试设置我的 graphql resover 来处理一组对象,但无法配置 @Args 装饰器。

我创建了自己的 ArgsType

import { ArgsType, Field, Int, ObjectType } from '@nestjs/graphql';

@ArgsType()  // to be used as type in the resolver
@ObjectType()  // for schema generation 
export class Club {
 @Field(type => String)
 president: string;

 @Field(type => Int)
 members?: number;
}
Run Code Online (Sandbox Code Playgroud)

添加单个俱乐部的解析器工作正常!

 @Query(() => Int)
 async addClub(@Args() club: Club) {
  // handle stuff
  }
Run Code Online (Sandbox Code Playgroud)

但如果我想像这样提供一系列俱乐部

 @Query(() => Int)
   async addClubs(@Args({name: 'clubs', type: () => [Club]}) clubs: Array<Club>) {
   // handle stuff
  }
Run Code Online (Sandbox Code Playgroud)

这在 Nest …

typescript graphql nestjs

9
推荐指数
1
解决办法
2502
查看次数

如何在 Flutter 测试中模拟 Socket.io 客户端

socket_io_client在我的 flutter 应用程序中使用 v0.9.12 (仍然没有使用空安全)。当应用程序启动时,我正在与后端服务器创建套接字连接,并允许子小部件使用提供程序访问它。

\n

我试图开始在构造函数中创建连接,以便当我需要使用套接字客户端时,它可能已经初始化了。

\n

这是我的提供程序类,它创建了套接字连接:

\n
class SocketClient {\n  SocketClient() {\n    _initializer = initialize();\n  }\n\n  Future _initializer;\n\n  /// Socket client\n  Socket client;\n\n  /// Wait until the client is properly connected with the server\n  Future finishInitializing() => _initializer;\n\n  /// Initialize the socket connection with the server\n  Future initialize() async {\n    final completer = Completer<Socket>();\n\n    final socket = io(\n      \'http://localhost:3000/gateway\',\n      OptionBuilder() //\n          .setTransports([\'websocket\'])\n          .disableAutoConnect()\n          .setQuery({\'token\': \'TOKEN\'})\n          .build(),\n    )..connect();\n\n    socket\n      ..onConnect((_) {\n        completer.complete(socket);\n      });\n\n    client = await …
Run Code Online (Sandbox Code Playgroud)

socket.io dart flutter flutter-test flutter-provider

9
推荐指数
1
解决办法
1534
查看次数

我们如何在 Nginx Ingress Controller 上安装动态模块(官方不支持)?(地形,舵图)

我正在管理 Kubernetes + nginx。我想在 Nginx 入口控制器提供的 nginx 上安装动态模块。这些动态模块不是由 Nginx Ingress Controller 官方配置映射提供的(https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/configmap/

所以我想我需要构建自己的 Nginx Ingress Controller Docker 容器。(可能会在此添加?https://github.com/kubernetes/ingress-nginx/blob/8951b7e22ad3952c549150f61d7346f272c563e1/images/nginx/rootfs/build.sh#L618-L632)你知道如何自定义控制器和管理它由掌舵图?我正在考虑从 Github 上的控制器主存储库创建一个 Fork 分支。但我不知道我们如何在 terraform + helm chart 上安装定制版本的控制器。

但是,我更喜欢使用不可定制的解决方案(因为一些注释设置......)

谢谢你。

环境:Kubernetes Nginx Ingress Controller 通过 helm chart + terraform Nginx Ingress Controller 安装 -> https://github.com/kubernetes/ingress-nginx/tree/main/charts/ingress-nginx

地形:

resource "helm_release" "nginx-ingress-controller" {
  name      = "nginx-ingress-controller"
  chart     = "ingress-nginx/ingress-nginx"
  namespace = "kube-system"
  version   = "3.34.0"
}
Run Code Online (Sandbox Code Playgroud)

动态模块 https://docs.nginx.com/nginx/admin-guide/dynamic-modules/dynamic-modules/ (安装过程可能是使用--add-dynamic-module选项,并且集合load_module modules/something.songinx.conf通过ingress.yaml

nginx docker kubernetes kubernetes-ingress nginx-ingress

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

如何在 GraphQL 中的解析器中获取输入类型的数组

我想ids从查询变量中获取一个字符串数组作为参数并在我的解析器中使用。下面是我的代码。

People.resolver.ts

import {
  Resolver, Query, Mutation, Args,
} from '@nestjs/graphql';
import { People } from './People.entity';
import { PeopleService } from './People.service';

@Resolver(() => People)
export class PeopleResolver {
  constructor(private readonly peopleService: PeopleService) { }

  @Mutation(() => String)
  async deletePeople(@Args('ids') ids: string[]) : Promise<String> {
    const result = await this.peopleService.deletePeople(ids);
    return JSON.stringify(result);
  }
}
Run Code Online (Sandbox Code Playgroud)

但是,我收到以下错误,

[Nest] 8247   - 06/22/2020, 6:32:53 PM   [RouterExplorer] Mapped {/run-migrations, POST} route +1ms
(node:8247) UnhandledPromiseRejectionWarning: Error: You need to provide explicit type for …
Run Code Online (Sandbox Code Playgroud)

rest typescript graphql graphql-js nestjs

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

如何在 Docker 中安装字体?

如何安装所有语言的字体?这就是我所做的,但 Chrome 中没有日文字体。

来自这张图片:https : //github.com/Zenika/alpine-chrome/blob/master/Dockerfile

FROM zenika/alpine-chrome

USER root

RUN apk add --no-cache msttcorefonts-installer fontconfig
RUN update-ms-fonts

# Installs latest Chromium package.
RUN apk add --no-cache \
    msttcorefonts-installer fontconfig \
    font-noto \
    font-noto-adlam \
    font-noto-adlamunjoined \
    font-noto-arabic \
    font-noto-armenian \
    font-noto-avestan \
    font-noto-bamum \
    font-noto-bengali \
    font-noto-buhid \
    font-noto-carian \
    font-noto-chakma \
    font-noto-cherokee \
    font-noto-cypriot \
    font-noto-deseret \
    font-noto-devanagari \
    font-noto-ethiopic \
    font-noto-extra \
    font-noto-georgian \
    font-noto-glagolitic \
    font-noto-gothic \
    font-noto-gujarati \
    font-noto-gurmukhi \
    font-noto-hebrew \
    font-noto-kannada \ …
Run Code Online (Sandbox Code Playgroud)

google-chrome chromeless docker alpine-linux

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

在“initState”内或在类定义下方初始化变量?

我想知道当我知道StateFlutter中类中变量的初始值时,我应该使用变量定义还是内部来初始化它initState方法。什么更好,为什么?

第一种方法:

class _SampleState extends State<Sample> {
  String _foo = 'FOO';

  @override
  void initState() {
    // Do some other stuff
    super.initState();
  }

  ...
}
Run Code Online (Sandbox Code Playgroud)

第二种方法:

class _SampleState extends State<Sample> {
  String _foo;

  @override
  void initState() {
    _foo = 'FOO';
    // Do some other stuff
    super.initState();
  }

  ...
}
Run Code Online (Sandbox Code Playgroud)

dart flutter

5
推荐指数
1
解决办法
589
查看次数

Redis 运行在保护模式下

我正在尝试在 4 个虚拟机上运行扩展 Yahoo Benchmark。每次我尝试运行“STORM_TEST”时都会收到以下错误。我尝试配置“redis.conf”但仍然遇到相同的错误。我在下面显示了错误和我的“redis.conf”文件。

错误:

Caused by: java.lang.Exception: DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients. In this mode connections are only accepted from the loopback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions: 1) Just disable protected mode sending the command 'CONFIG SET protected-mode no' from the loopback interface by connecting …
Run Code Online (Sandbox Code Playgroud)

streaming benchmarking configuration redis

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

运行测试时出现“未找到:'dart:js'导出'dart:js'显示allowInterop,allowInteropCaptureThis”错误

在我的 Flutter 应用程序中,我有一个名为 的文件web.dart,其中有一个webSaveAs函数可以将文件保存到 web 中的本地计算机上。

\n
@JS()\nlibrary main;\n\nimport \'package:js/js.dart\';\nimport \'package:universal_html/html.dart\';\n\n/// Annotate `webSaveAs` to invoke JavaScript `window.webSaveAs`\n@JS(\'webSaveAs\')\nexternal void webSaveAs(Blob blob, String fileName);\n
Run Code Online (Sandbox Code Playgroud)\n

但是,当我运行任何导入flutter test我使用过webSaveAs功能的小部件的测试(使用命令)时,出现以下错误:

\n
./../../../development/flutter/.pub-cache/hosted/pub.dartlang.org/js-0.6.3-nullsafety.3/lib/js.dart:8:1: Error: Not found: \'dart:js\'\nexport \'dart:js\' show allowInterop, allowInteropCaptureThis;\n^\n
Run Code Online (Sandbox Code Playgroud)\n

我正在使用js: ^0.6.2https://pub.dev/packages/js 这是命令的结果flutter doctor

\n
\xe2\x95\xb0>>> flutter doctor\nDoctor summary (to see all details, run flutter doctor -v):\n[\xe2\x9c\x93] Flutter (Channel beta, 1.25.0-8.3.pre, on macOS 11.2.1 20D74 darwin-x64, locale en-SG)\n[\xe2\x9c\x93] Android toolchain - …
Run Code Online (Sandbox Code Playgroud)

dart flutter flutter-test flutter-web

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

配置Oprofile时出现"bfd library not found"错误

我下载了oprofile zip,然后将其解压缩.然后使用命令./configure --prefix=/home/eranga/Software/oprofile-1.1.0我试图安装它.下面是最后一个控制台信息.

checking for bfd_openr in -lbfd... no checking for compress in -lz... yes checking for bfd_fdopenr in -lbfd... no configure: error: bfd library not found

任何人都可以建议为什么会这样,并解决它.提前致谢 :-)

ubuntu profiling oprofile

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

在 NestJS 中连接后,Socket.io 客户端断开连接

我正在尝试使用 nestjs 创建聊天,但它的问题在于@SubscribeMessage()连接的实现正在工作,但是当我尝试侦听来自前端的发射和consolenestjs 中的数据时,它不起作用

import { Server, Socket } from 'socket.io';
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { User } from '../entities/user.entity';
import { Repository } from 'typeorm';
import { Messenger } from './entities/messenger.entity';

@Injectable()
@WebSocketGateway(5000)
export class MessengerGateway implements OnGatewayConnection, OnGatewayDisconnect, OnGatewayInit {
  constructor(
    @InjectRepository(User)
    private userRepository: Repository<User>,
    @InjectRepository(Messenger)
    private messageRepository: Repository<Messenger>,
  ) {}

  @SubscribeMessage('loadPeople')
  handleEvent(client: Socket, data){
    console.log(data);
    // this is not working
  }

  async afterInit(server: Server) …
Run Code Online (Sandbox Code Playgroud)

websocket socket.io reactjs nestjs nestjs-gateways

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

计数器变量作为Python中for循环的步长值

在Java中,我们可以在其标题本身内更改for循环的计数器变量.见下文:

for(int i=1; i<1024; i*=2){
    System.out.println(i);
}
Run Code Online (Sandbox Code Playgroud)

我知道以下代码是错误的.但有没有一种方法可以在不改变i循环内部值的情况下编写.我喜欢让我的for循环简单而简短:-)

for i in range(1, 1024, i*=2):        
    print(i)
Run Code Online (Sandbox Code Playgroud)

python loops python-3.x

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