zoukankan      html  css  js  c++  java
  • Dart: 请求graphql数据

    import 'package:http/http.dart' as http;
    const url = "http://127.0.0.1:4000/graphql";
    main(List<String> args) async {
      cat("b");
    }
    
    cat(String name) async {
      String query = '''
      query {
        cat(name: "$name") {
          name 
          age
        }
       }
      ''';
      String u = "${url}?query=${query}";
      var r = await http.post(u);
      print(r.body);
    }
    
    const l = console.log;
    var express = require('express');
    var graphqlHTTP = require('express-graphql');
    var {buildSchema} = require('graphql');
    
    const cats = [{name: 'a', age: 12}, {name: 'b', age: 13}, {name: 'c', age: 14}];
    
    var schema = buildSchema(`
      type Query {
        cat(name: String): Cat
      }
    
      type Cat {
        name: String
        age: Int
      }
    `);
    
    var root = {
      cat({name}) {
        return cats.find(el => el.name === name.trim());
      },
    };
    
    var app = express();
    
    app.use(
      '/graphql',
      graphqlHTTP({
        schema: schema,
        rootValue: root,
        graphiql: true,
      }),
    );
    app.listen(4000);
    
  • 相关阅读:
    Qt环境搭建(Visual Studio)
    HTML基础
    关于Qt
    I am back
    Node Security
    Mobile Assistant
    Home Server
    抉择-什么最重要
    在一个JSP页面中包含另一个JSP页面的三种方式
    JS控制DIV隐藏显示
  • 原文地址:https://www.cnblogs.com/ajanuw/p/10972770.html
Copyright © 2011-2022 走看看