fix: adding missing files in react-apollo example
This commit is contained in:
parent
9bcebf17f6
commit
f9b724478b
|
@ -0,0 +1,23 @@
|
|||
import React from "react";
|
||||
import {useQuery} from "@apollo/react-hooks";
|
||||
import {MY_QUERY} from "./queries";
|
||||
|
||||
const MyEvent = () => {
|
||||
const {loading, error, data} = useQuery(MY_QUERY);
|
||||
if (loading) return <div>No data available...</div>;
|
||||
if (error) {
|
||||
console.error(error);
|
||||
return <div>Error :(</div>;
|
||||
}
|
||||
return (
|
||||
<div>
|
||||
<p>The data returned by the query:</p>
|
||||
<ul>
|
||||
<li>someValue: {data.myEvents.someValue}</li>
|
||||
<li>anotherValue: {data.myEvents.anotherValue}</li>
|
||||
</ul>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default MyEvent;
|
|
@ -0,0 +1,10 @@
|
|||
import gql from "graphql-tag";
|
||||
|
||||
export const MY_QUERY = gql`
|
||||
query @live {
|
||||
myEvents {
|
||||
someValue
|
||||
anotherValue
|
||||
}
|
||||
}
|
||||
`;
|
|
@ -0,0 +1,23 @@
|
|||
import {makeExecutableSchema} from "graphql-tools";
|
||||
|
||||
const getSchema = MyContractInstance => {
|
||||
const typeDefs = `
|
||||
type MyEvent {
|
||||
someValue: String
|
||||
anotherValue: String
|
||||
}
|
||||
type Query {
|
||||
myEvents: MyEvent!
|
||||
}
|
||||
`;
|
||||
|
||||
const resolvers = {
|
||||
Query: {
|
||||
myEvents: () => MyContractInstance.events.MyEvent.track({filter: {}, fromBlock: 1})
|
||||
}
|
||||
};
|
||||
|
||||
return makeExecutableSchema({typeDefs, resolvers});
|
||||
};
|
||||
|
||||
export default getSchema;
|
|
@ -1,12 +1,12 @@
|
|||
const Subspace = require('@embarklabs/subspace').default;
|
||||
const web3 = require('./web3');
|
||||
const MyContract = require('./MyContract');
|
||||
const { pluck } = require('rxjs/operators');
|
||||
const { makeExecutableSchema } = require("graphql-tools");
|
||||
const Subspace = require("@embarklabs/subspace").default;
|
||||
const web3 = require("./web3");
|
||||
const MyContract = require("./MyContract");
|
||||
const {pluck} = require("rxjs/operators");
|
||||
const {makeExecutableSchema} = require("graphql-tools");
|
||||
const gql = require("graphql-tag");
|
||||
const { graphql } = require("reactive-graphql");
|
||||
const {graphql} = require("reactive-graphql");
|
||||
|
||||
const run = (async () => {
|
||||
const run = async () => {
|
||||
const subspace = new Subspace(web3);
|
||||
await subspace.init();
|
||||
|
||||
|
@ -31,12 +31,12 @@ const run = (async () => {
|
|||
const resolvers = {
|
||||
Query: {
|
||||
myEvents: () => {
|
||||
return subspace.trackEvent(MyContractInstance, 'MyEvent', {filter: {}, fromBlock: 1})
|
||||
return subspace.trackEvent(MyContractInstance, "MyEvent", {filter: {}, fromBlock: 1});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const schema = makeExecutableSchema({ typeDefs, resolvers });
|
||||
const schema = makeExecutableSchema({typeDefs, resolvers});
|
||||
|
||||
const query = gql`
|
||||
query {
|
||||
|
@ -47,11 +47,10 @@ const run = (async () => {
|
|||
}
|
||||
`;
|
||||
|
||||
const stream = graphql(schema, query).pipe(pluck('data', 'myEvents'));
|
||||
const stream = graphql(schema, query).pipe(pluck("data", "myEvents"));
|
||||
stream.subscribe(x => {
|
||||
console.log(x)
|
||||
console.log(x);
|
||||
});
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
run();
|
||||
|
|
Loading…
Reference in New Issue