简体   繁体   中英

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

I write a simple demo for your question. You can check this: https://codesandbox.io/s/n7vqnovl8l

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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