简体   繁体   English

ReactJS / GraphQL:显示查询数据

[英]ReactJS/GraphQL: Display data from query

So after I click on the submit button nothing happens. 因此,在我单击“提交”按钮后,没有任何反应。 I am not sure if the query is being execute or not. 我不确定查询是否正在执行。 If it is how do I display the the results in the browser? 如果是的话,如何在浏览器中显示结果?

The submit button 提交按钮

handleSubmit(event) {
  event.preventDefault();
  console.log(this.state.inputValue)
  this.state = {
    inputValue: new Date(document.getElementById("time").value).valueOf()
  };
  ObjectQuery({
    variables: {
      timestamp: this.state.inputValue
    }
  });
}

The query component 查询组件

import gql from "graphql-tag";

export function ObjectQuery() {
  gql`
    query($timestamp: Float!) {
      action(timestamp: $timestamp) {
        action
        timestamp
        object {
          filename
        }
      }
    }
  `;
}

export default ObjectQuery;

You need return gql in your ObjectQuery function 您需要在ObjectQuery函数中返回gql

I write a simple demo for your question. 我为您的问题编写了一个简单的演示。 You can check this: https://codesandbox.io/s/n7vqnovl8l 您可以检查以下内容: https : //codesandbox.io/s/n7vqnovl8l

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM