forked from cerc-io/laconic-console
Test mutation.
This commit is contained in:
@@ -6,17 +6,36 @@ type JSONResult {
|
||||
json: String!
|
||||
}
|
||||
|
||||
type Log {
|
||||
log: [String]!
|
||||
}
|
||||
|
||||
type Status {
|
||||
timestamp: String!
|
||||
version: String!
|
||||
}
|
||||
|
||||
type Result {
|
||||
timestamp: String!
|
||||
code: Int!
|
||||
}
|
||||
|
||||
#
|
||||
# Schema
|
||||
#
|
||||
|
||||
type Query {
|
||||
status: Status
|
||||
ipfs: JSONResult
|
||||
wns: JSONResult
|
||||
system_status: Status
|
||||
ipfs_status: JSONResult
|
||||
wns_status: JSONResult
|
||||
wns_log: Log
|
||||
}
|
||||
|
||||
type Mutation {
|
||||
wns_action(command: String!): Result
|
||||
}
|
||||
|
||||
schema {
|
||||
mutation: Mutation
|
||||
query: Query
|
||||
}
|
||||
|
||||
@@ -10,9 +10,9 @@ import yaml from 'js-yaml';
|
||||
import { ApolloServer, gql } from 'apollo-server-express';
|
||||
import { print } from 'graphql/language';
|
||||
|
||||
import QUERY_STATUS from '@dxos/console-client/gql/status.graphql';
|
||||
import SYSTEM_STATUS from '@dxos/console-client/gql/system_status.graphql';
|
||||
|
||||
import { resolvers } from './resolvers';
|
||||
import { createResolvers } from './resolvers';
|
||||
|
||||
import SCHEMA from './gql/api.graphql';
|
||||
|
||||
@@ -60,7 +60,8 @@ app.get(`${publicUrl}(/:filePath)?`, (req, res) => {
|
||||
|
||||
const server = new ApolloServer({
|
||||
typeDefs: SCHEMA,
|
||||
resolvers,
|
||||
|
||||
resolvers: createResolvers(config),
|
||||
|
||||
// https://www.apollographql.com/docs/apollo-server/testing/graphql-playground
|
||||
// https://github.com/prisma-labs/graphql-playground#usage
|
||||
@@ -73,7 +74,7 @@ const server = new ApolloServer({
|
||||
{
|
||||
name: 'Status',
|
||||
endpoint: config.api.path,
|
||||
query: print(gql(QUERY_STATUS))
|
||||
query: print(gql(SYSTEM_STATUS))
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -13,13 +13,31 @@ const log = debug('dxos:console:server:resolvers');
|
||||
// Resolvers
|
||||
//
|
||||
|
||||
export const resolvers = {
|
||||
const timestamp = () => new Date().toUTCString();
|
||||
|
||||
export const createResolvers = config => ({
|
||||
Mutation: {
|
||||
//
|
||||
// WNS
|
||||
//
|
||||
|
||||
wns_action: async (_, __, { action }) => {
|
||||
log(`WNS action: ${action}`);
|
||||
|
||||
return {
|
||||
timestamp: timestamp(),
|
||||
code: 0
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
Query: {
|
||||
//
|
||||
// Status
|
||||
// System
|
||||
//
|
||||
status: () => ({
|
||||
timestamp: new Date().toUTCString(),
|
||||
|
||||
system_status: () => ({
|
||||
timestamp: timestamp(),
|
||||
version
|
||||
}),
|
||||
|
||||
@@ -29,15 +47,20 @@ export const resolvers = {
|
||||
// https://github.com/ipfs/js-ipfs
|
||||
// https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-http-client#api
|
||||
//
|
||||
ipfs: async () => {
|
||||
|
||||
ipfs_status: async () => {
|
||||
log('Calling IPFS...');
|
||||
|
||||
// TODO(burdon): Config.
|
||||
// NOTE: Hangs if server not running.
|
||||
const ipfs = new IpfsHttpClient('/ip4/127.0.0.1/tcp/5001');
|
||||
|
||||
const version = await ipfs.version();
|
||||
const status = await ipfs.id();
|
||||
|
||||
console.log(version);
|
||||
log('Done');
|
||||
|
||||
return {
|
||||
json: JSON.stringify({
|
||||
version,
|
||||
@@ -46,4 +69,4 @@ export const resolvers = {
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user