-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #316 from cofacts/feature/ydoc
Implement GetYdoc query and Ydoc model
- Loading branch information
Showing
7 changed files
with
157 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { GraphQLObjectType, GraphQLString, GraphQLList } from 'graphql'; | ||
|
||
import YdocVersion from './YdocVersion'; | ||
|
||
const Ydoc = new GraphQLObjectType({ | ||
name: 'Ydoc', | ||
fields: () => ({ | ||
data: { | ||
type: GraphQLString, | ||
// https://www.elastic.co/guide/en/elasticsearch/reference/current/binary.html | ||
description: 'Binary that stores as base64 encoded string', | ||
}, | ||
versions: { | ||
type: new GraphQLList(YdocVersion), | ||
description: | ||
'Ydoc snapshots which are used to restore to specific version', | ||
resolve: async ({ versions }) => { | ||
return versions || []; | ||
}, | ||
}, | ||
}), | ||
}); | ||
|
||
export default Ydoc; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { GraphQLObjectType, GraphQLString } from 'graphql'; | ||
|
||
export default new GraphQLObjectType({ | ||
name: 'YdocVersion', | ||
fields: () => ({ | ||
createdAt: { type: GraphQLString }, | ||
snapshot: { | ||
type: GraphQLString, | ||
// https://www.elastic.co/guide/en/elasticsearch/reference/current/binary.html | ||
description: 'Binary that stores as base64 encoded string', | ||
}, | ||
}), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { GraphQLString, GraphQLNonNull } from 'graphql'; | ||
|
||
import Ydoc from 'graphql/models/Ydoc'; | ||
|
||
export default { | ||
type: Ydoc, | ||
args: { | ||
id: { type: new GraphQLNonNull(GraphQLString) }, | ||
}, | ||
resolve: async (rootValue, { id }, { loaders }) => | ||
loaders.docLoader.load({ index: 'ydocs', id }), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
export default { | ||
'/ydocs/doc/foo': { | ||
data: 'mock data1', | ||
versions: [ | ||
{ | ||
createdAt: '2023-09-07T08:14:14.005Z', | ||
snapshot: 'mock snapshot1', | ||
}, | ||
{ | ||
createdAt: '2023-09-07T08:16:45.613Z', | ||
snapshot: 'mock snapshot2', | ||
}, | ||
{ | ||
createdAt: '2023-09-07T08:18:32.467Z', | ||
snapshot: 'mock snapshot3', | ||
}, | ||
{ | ||
createdAt: '2023-09-07T08:18:49.500Z', | ||
snapshot: 'mock snapshot4', | ||
}, | ||
], | ||
}, | ||
'/ydocs/doc/foo2': { | ||
data: 'mock data2', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import gql from 'util/GraphQL'; | ||
import { loadFixtures, unloadFixtures } from 'util/fixtures'; | ||
import fixtures from '../__fixtures__/GetYdoc'; | ||
|
||
describe('GetYdoc', () => { | ||
beforeAll(() => loadFixtures(fixtures)); | ||
afterAll(() => unloadFixtures(fixtures)); | ||
|
||
it('should get the specified doc', async () => { | ||
expect( | ||
await gql` | ||
{ | ||
GetYdoc(id: "foo") { | ||
data | ||
versions { | ||
createdAt | ||
snapshot | ||
} | ||
} | ||
} | ||
`({}, { user: { id: 'test', appId: 'test' } }) | ||
).toMatchSnapshot(); | ||
}); | ||
|
||
it('should return empty versions when there is none', async () => { | ||
expect( | ||
await gql` | ||
{ | ||
GetYdoc(id: "foo2") { | ||
data | ||
versions { | ||
createdAt | ||
snapshot | ||
} | ||
} | ||
} | ||
`({}, { user: { id: 'test', appId: 'test' } }) | ||
).toMatchSnapshot(); | ||
}); | ||
}); |
40 changes: 40 additions & 0 deletions
40
src/graphql/queries/__tests__/__snapshots__/GetYdoc.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`GetYdoc should get the specified doc 1`] = ` | ||
Object { | ||
"data": Object { | ||
"GetYdoc": Object { | ||
"data": "mock data1", | ||
"versions": Array [ | ||
Object { | ||
"createdAt": "2023-09-07T08:14:14.005Z", | ||
"snapshot": "mock snapshot1", | ||
}, | ||
Object { | ||
"createdAt": "2023-09-07T08:16:45.613Z", | ||
"snapshot": "mock snapshot2", | ||
}, | ||
Object { | ||
"createdAt": "2023-09-07T08:18:32.467Z", | ||
"snapshot": "mock snapshot3", | ||
}, | ||
Object { | ||
"createdAt": "2023-09-07T08:18:49.500Z", | ||
"snapshot": "mock snapshot4", | ||
}, | ||
], | ||
}, | ||
}, | ||
} | ||
`; | ||
|
||
exports[`GetYdoc should return empty versions when there is none 1`] = ` | ||
Object { | ||
"data": Object { | ||
"GetYdoc": Object { | ||
"data": "mock data2", | ||
"versions": Array [], | ||
}, | ||
}, | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters