Skip to content

Commit e062a83

Browse files
Merge pull request #296 from aws/temp
Couple of minor doc fixes with @searchable
2 parents c8df8e4 + fb27702 commit e062a83

3 files changed

Lines changed: 110 additions & 39 deletions

File tree

amplifycli_react_tutorial.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ If you're using Windows, we recommend the [Windows Subsystem for Linux](https://
1111

1212
- An AWS Account and credentials are required. For more information about how to find your credentials, see [AWS Mobile CLI User Credentials](https://docs.aws.amazon.com/aws-mobile/latest/developerguide/aws-mobile-cli-credentials.html) in the *AWS Mobile User Guide*.
1313
- Ensure that you have Node.js installed.
14+
- Ensure that you have [lerna](https://github.com/lerna/lerna) installed globally.
1415
- Download the Amplify CLI from [HERE](https://s3.amazonaws.com/amplify-cli-beta-3dd89264-8c7c-11e8-9eb6-529269fb1459/amplify-cli-0.1.0-8-8-18.tgz).
1516
- Go to the unpacked directory (usually called `package`) and run `npm run setup-dev`
1617
- Ensure you have [Create React App](https://github.com/facebook/create-react-app) installed.
@@ -127,6 +128,7 @@ Now that your application is set up, it's time to add a backend API with data th
127128
- `@model` for storing types in Amazon DynamoDB.
128129
- `@auth` to define different authorization strategies.
129130
- `@connection` for specifying relationships between `@model` object types.
131+
- `@searchable` for streaming the data of an `@model` object type to Amazon Elasticsearch Service.
130132

131133
To get started run `amplify add api` and select `GraphQL`. When prompted, choose `Amazon Cognito User Pool` and the project will leverage your existing authentication setup. For `annotated schema`, choose **No**. For `guided schema creation`, choose **Yes**.
132134

graphql-transform-tutorial.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ And then search for posts
692692

693693
```graphql
694694
query SearchPosts {
695-
searchPost(filter: { title: { term: "Stream" }}) {
695+
searchPost(filter: { title: { match: "Stream" }}) {
696696
items {
697697
id
698698
title

packages/graphql-transformers-e2e-tests/src/__tests__/SearchableModelTransformer.e2e.test.ts

Lines changed: 107 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,44 @@ import { GraphQLClient } from '../GraphQLClient'
1414

1515
jest.setTimeout(60000 * 60);
1616

17+
const s3 = new S3Client('us-west-2')
1718
const cf = new CloudFormationClient('us-west-2')
1819
const STACK_NAME = 'TestSearchableModelTransformer'
1920
const BUCKET_NAME = 'testSearchableModelTransformer'
2021
const FUNCTION_NAME = 'python_streaming_function.zip'
2122
const FUNCTION_PATH = `${__dirname}/../../node_modules/graphql-elasticsearch-transformer/streaming-lambda.zip`
2223

23-
const s3 = new S3Client('us-west-2')
24-
25-
let GRAPHQL_CLIENT = undefined;
24+
const createPosts = async () => {
25+
await GRAPHQL_CLIENT.query(getCreatePostsQuery(
26+
"snvishna", "test", 157, 10, 97.4, true
27+
), {})
28+
await GRAPHQL_CLIENT.query(getCreatePostsQuery(
29+
"snvishna", "test title", 60, 30, 21.0, false
30+
), {})
31+
await GRAPHQL_CLIENT.query(getCreatePostsQuery(
32+
"snvishna", "test title", 160, 30, 97.6, false
33+
), {})
34+
await GRAPHQL_CLIENT.query(getCreatePostsQuery(
35+
"snvishna", "test TITLE", 170, 30, 88.8, true
36+
), {})
37+
await GRAPHQL_CLIENT.query(getCreatePostsQuery(
38+
"snvishna", "test title", 200, 50, 11.9, false
39+
), {})
40+
await GRAPHQL_CLIENT.query(getCreatePostsQuery(
41+
"snvishna", "test title", 170, 30, 88.8, true
42+
), {})
43+
await GRAPHQL_CLIENT.query(getCreatePostsQuery(
44+
"snvishna", "test title", 160, 30, 97.6, false
45+
), {})
46+
await GRAPHQL_CLIENT.query(getCreatePostsQuery(
47+
"snvishna", "test title", 170, 30, 77.7, true
48+
), {})
2649

27-
function outputValueSelector(key: string) {
28-
return (outputs: Output[]) => {
29-
const output = outputs.find((o: Output) => o.OutputKey === key)
30-
return output ? output.OutputValue : null
31-
}
50+
// Waiting for the ES Cluster + Streaming Lambda infra to be setup
51+
await cf.wait(120, () => Promise.resolve())
3252
}
3353

34-
beforeAll(async () => {
54+
const setup = async () => {
3555
const validSchema = `
3656
type Post @model @searchable {
3757
id: ID!
@@ -66,13 +86,22 @@ beforeAll(async () => {
6686
expect(apiKey).toBeDefined()
6787
expect(endpoint).toBeDefined()
6888
GRAPHQL_CLIENT = new GraphQLClient(endpoint, { 'x-api-key': apiKey })
69-
} catch (e) {
89+
90+
// Create sample mutations to test search queries
91+
createPosts();
92+
} catch (e: AlreadyExistsException) {
93+
console.log('Setup failed with AlreadyExistsException, cleaning up resources. ' + e)
94+
await cleanup()
95+
96+
console.log('Calling Setup again')
97+
await setup()
98+
} catch (e: Exception) {
7099
console.error(e)
71100
expect(true).toEqual(false)
72101
}
73-
});
102+
}
74103

75-
afterAll(async () => {
104+
const cleanup = async () => {
76105
try {
77106
console.log('Deleting S3 resources')
78107
await s3.cleanUpS3Resources(BUCKET_NAME, FUNCTION_NAME)
@@ -92,33 +121,14 @@ afterAll(async () => {
92121
expect(true).toEqual(false)
93122
}
94123
}
95-
})
124+
}
96125

97-
test('Test createPost mutation', async () => {
98-
try {
99-
await cf.wait(120, () => Promise.resolve())
100-
101-
const response = await GRAPHQL_CLIENT.query(`mutation {
102-
createPost(input: { title: "Hello, World!" }) {
103-
id
104-
title
105-
createdAt
106-
updatedAt
107-
}
108-
}`, {})
109-
console.log('createPost: ' + JSON.stringify(response, null, 4))
110-
expect(response.data.createPost.id).toBeDefined()
111-
expect(response.data.createPost.title).toEqual('Hello, World!')
112-
expect(response.data.createPost.createdAt).toBeDefined()
113-
expect(response.data.createPost.updatedAt).toBeDefined()
114-
} catch (e) {
115-
console.error(e)
116-
// fail
117-
expect(e).toBeUndefined()
118-
}
119-
})
126+
let GRAPHQL_CLIENT = undefined;
120127

121-
test('Test searchPost query', async () => {
128+
beforeAll(setup);
129+
afterAll(cleanup);
130+
131+
test('Test searchPost query without filter', async () => {
122132
try {
123133
await GRAPHQL_CLIENT.query(`mutation {
124134
createPost(input: { title: "Hello, World 2!" }) {
@@ -139,7 +149,7 @@ test('Test searchPost query', async () => {
139149
}
140150
}
141151
}`, {})
142-
console.log('searchPost: ' + JSON.stringify(response, null, 4))
152+
console.log('Test searchPost query without filter: ' + JSON.stringify(response, null, 4))
143153
expect(response).toBeDefined
144154
expect(response.data.searchPost.items).toBeDefined
145155
const items = response.data.searchPost.items
@@ -151,6 +161,30 @@ test('Test searchPost query', async () => {
151161
}
152162
})
153163

164+
test('Test searchPost query with basic filter', async () => {
165+
try {
166+
const response = await GRAPHQL_CLIENT.query(`query {
167+
searchPost(filter: {
168+
author: { eq: "snvishna" }
169+
}) {
170+
items {
171+
id
172+
title
173+
}
174+
}
175+
}`, {})
176+
console.log('Test searchPost query with basic filter: ' + JSON.stringify(response, null, 4))
177+
expect(response).toBeDefined
178+
expect(response.data.searchPost.items).toBeDefined
179+
const items = response.data.searchPost.items
180+
expect(items.length).toEqual(8)
181+
} catch (e) {
182+
console.error(e)
183+
// fail
184+
expect(e).toBeUndefined()
185+
}
186+
})
187+
154188
function generateParams() {
155189
const params = {
156190
[ResourceConstants.PARAMETERS.ElasticSearchStreamingLambdaCodeS3Bucket]: BUCKET_NAME,
@@ -161,3 +195,38 @@ function generateParams() {
161195

162196
return params
163197
}
198+
199+
function getCreatePostsQuery(
200+
author: string,
201+
title: string,
202+
ups: number,
203+
downs: number,
204+
percantageUp: number,
205+
isPublished: boolean
206+
): string {
207+
return `mutation {
208+
createPost(input: {
209+
author: ${author}
210+
title: ${title}
211+
ups: ${ups}
212+
downs: ${downs}
213+
percentageUp: ${percantageUp}
214+
isPublished: ${isPublished}
215+
}) {
216+
id
217+
author
218+
title
219+
ups
220+
downs
221+
percentageUp
222+
isPublished
223+
}
224+
}`
225+
}
226+
227+
function outputValueSelector(key: string) {
228+
return (outputs: Output[]) => {
229+
const output = outputs.find((o: Output) => o.OutputKey === key)
230+
return output ? output.OutputValue : null
231+
}
232+
}

0 commit comments

Comments
 (0)