Skip to content
This repository was archived by the owner on Oct 8, 2024. It is now read-only.

Commit eb27fc9

Browse files
Update examples (#59)
* Update example functions * Update example schema
1 parent eb36622 commit eb27fc9

File tree

2 files changed

+12
-60
lines changed

2 files changed

+12
-60
lines changed

examples/hmplugin1/assembly/index.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,11 @@ export function queryPeople2(): Person[] {
7373
id
7474
firstName
7575
lastName
76-
fullName
7776
}
7877
}
7978
`;
8079

8180
const results = graphql.execute<PeopleData>(statement);
82-
83-
// completely optional, but let's log some tracing info
84-
const tracing = results.extensions!.tracing;
85-
const duration = tracing.duration / 1000000.0;
86-
console.log(`Start: ${tracing.startTime.toISOString()}`);
87-
console.log(`End: ${tracing.endTime.toISOString()}`);
88-
console.log(`Duration: ${duration}ms`);
89-
9081
return results.data.people;
9182
}
9283

@@ -105,19 +96,23 @@ export function newPerson1(firstName: string, lastName: string): string {
10596
return response.data.uids.get("x");
10697
}
10798

108-
export function newPerson2(firstName: string, lastName: string): string {
99+
export function newPerson2(firstName: string, lastName: string): Person {
109100
const statement = `
110101
mutation {
111102
addPerson(input: [{firstName: "${firstName}", lastName: "${lastName}" }]) {
112103
people: person {
113104
id
105+
firstName
106+
lastName
114107
}
115108
}
116109
}
117110
`;
118111

119112
const response = graphql.execute<AddPersonPayload>(statement);
120-
return response.data.addPerson.people[0].id!;
113+
const person = response.data.addPerson.people[0];
114+
person.updateFullName();
115+
return person;
121116
}
122117

123118
function getPersonCount(): i32 {
@@ -142,13 +137,14 @@ export function getRandomPerson(): Person {
142137
id
143138
firstName
144139
lastName
145-
fullName
146140
}
147141
}
148142
`;
149143

150144
const results = graphql.execute<PeopleData>(statement);
151-
return results.data.people[0];
145+
const person = results.data.people[0];
146+
person.updateFullName();
147+
return person;
152148
}
153149

154150
export function testClassifier(

examples/hmplugin1/schema.graphql

Lines changed: 3 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,9 @@
1-
# This sample schema shows how to use the functions defined in this plugin.
2-
3-
# this directive will eventually be built-in, and will replace @lambda
4-
directive @hm_function(name: String, args: [String!]) on FIELD_DEFINITION
5-
6-
type Query {
7-
add(a: Int!, b: Int!): Int! @lambda @hm_function
8-
getFullName(firstName: String!, lastName: String!): String! @lambda @hm_function
9-
getPeople: [Person!]! @lambda @hm_function
10-
queryPeople1: [Person!]! @lambda @hm_function
11-
queryPeopleWithVars(firstName: String!, lastName: String!): [Person!]! @lambda @hm_function
12-
queryPeople2: [Person!]! @lambda @hm_function
13-
getRandomPerson: Person! @lambda @hm_function
14-
testError: Int! @lambda @hm_function
15-
testClassifier(modelId: String!, text: String!): ClassificationResult! @lambda @hm_function
16-
testMultipleClassifier(modelId: String!, ids: String!, texts: String!): [ClassificationObject!]! @lambda @hm_function
17-
testEmbedding(modelId: String!, text: String!): String! @lambda @hm_function
18-
testEmbeddings(modelId: String!, ids: String!, texts: String!): [EmbeddingObject!]! @lambda @hm_function
19-
testTextGenerator(modelId: String!, instruction: String!, text: String!): String! @lambda @hm_function
20-
}
21-
22-
type Mutation {
23-
newPerson1(firstName: String!, lastName: String!): String! @lambda @hm_function
24-
newPerson2(firstName: String!, lastName: String!): String! @lambda @hm_function
25-
}
1+
# This sample schema is used for the examples that work with Dgraph.
2+
# It can be applied to Dgraph with some sample data using the
3+
# ./loaddata.sh script.
264

275
type Person {
286
id: ID!
297
firstName: String! @search(by: [hash])
308
lastName: String! @search(by: [hash])
31-
fullName: String @lambda @hm_function(name: "getFullName", args: ["firstName", "lastName"])
32-
}
33-
34-
type EmbeddingObject @remote {
35-
id: String
36-
text: String
37-
embedding: String
38-
}
39-
40-
type ClassificationObject @remote {
41-
id: String
42-
text: String
43-
result: ClassificationResult
44-
}
45-
46-
type ClassificationResult @remote {
47-
probabilities: [ClassificationProbability]
48-
}
49-
50-
type ClassificationProbability @remote {
51-
label: String
52-
probability: Float
539
}

0 commit comments

Comments
 (0)