Step 2— Using JSON-AI with GraphQL

Step 1: copy and paste these type definitions into your index.js file:

Ron Itelman
3 min readNov 4, 2018

--

//JSON-AI type definitions
const typeDefs = gql`
type Query {
agents: [Agent]
concepts: [Concept]
documents: [Document]
heroes: [Hero]
stories: [Story]
}

type Agent {
id: String!
description: String!
request: AgentRequest
}
type AgentRequest {
timestamp: String
url: String
method: String
query: String
data: String
}
type Concept {
id: String!
contexts: [ConceptContext]
}
type ConceptContext {
id: String!
}
type Document {
id: String!
url: String
knowledge: [Knowledge]
}
type Element {
id: String!
label: String
sentences: [Sentence]
}
type Epoch {
id: String!
documents: [Document]
heroes: [Hero]
agents: [Agent]
}
type Hero {
id: String!
firstName: String
lastName: String
}
type Knowledge {
id: String!
concepts: [Concept]
elements: [Element]
}
type Sentence {
id: String!
text: String!
}
type Story {
id: String!
epochs: [Epoch]
}
`;

Step 2: Update your resolvers

const resolvers = {
Query: {
agents: () => agents,
concepts: () => concepts,
documents: () => documents,
heroes: () => heroes,
stories: () => stories,
}
};

Step 3: Declare your GraphQL Object Values (Dummy Data)

let agents = [
{
id: "Apollo",
description: "GraphQL Server",
request: {
timestamp: "Nov 3 2018",
url:"localhost:4000",
method:"GraphQL",
query:"/api",
data: "JSON goes here"
}
},
{
id: "Synthesizer",
description: "JSON-AI Server",
request: {
timestamp: "Nov 3 2018",
url:"localhost:8001",
method:"GraphQL",
query:"/api",
data: "JSON goes here"
}
}
];
let concepts = [
{
id: "Board",
contexts: [
{ id:"Charter School Board" },
{ id: "Corporate Board" }
]
}
];
let documents = [
{
id:"Machine Teaching",
url: "https://medium.com/@ron_69694/machine-teaching-knowledge-snippets-98fcc01a4f79",
knowledge: [
{
id:"our first snippet",
concepts: [
{ id: "JSON-AI" },
{ id: "Machine Teaching Concepts" },
{ id: "Machine Learning Research" }
],
elements: [
{
id:"paragraph #",
label: "Definition 2.1",
sentences:[
{
id: "1",
text: "Definition 2.1 (Machine learning research) Machine Learning research aims at making the learner better by improving ML algorithms."
},
{
id: "2",
text: "This field covers, for instance, any new variations or breakthroughs in deep learning, unsupervised learning, recurrent networks, convex optimization, and so on."
},
{
id: "3",
text: "Conversely, we see version control, concept decomposition, semantic data exploration, expressiveness of the teaching language, interpretability of the model, and productivity as having more in common with programming and human-computer interaction than with machine learning."
},
{
id: "4",
text: "These \“machine teaching\” concepts, however, are extraordinarily important to any practitioners of machine learning."
},
{
id: "4",
text: "These \“machine teaching\” concepts, however, are extraordinarily important to any practitioners of machine learning."
},
]
}
]
}
]
}
]
let heroes = [
{
id: "1242",
firstName: "Bilbo",
lastName: "Baggins"
}
]
let stories = [
{
id: "_origin",
epochs: [
{
id:"epoch 1",
heroes: heroes,
documents: documents,
agents: agents
}
]
}
]

--

--

Ron Itelman

I like human + machine learning systems | Principal — Digital, Data & Analytics at Clarkston Consulting