Skip to content

Commit

Permalink
Merge 6aab45b into f98df43
Browse files Browse the repository at this point in the history
  • Loading branch information
nonumpa committed Sep 7, 2023
2 parents f98df43 + 6aab45b commit e593993
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/graphql/models/Ydoc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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),
},
}),
});

export default Ydoc;
13 changes: 13 additions & 0 deletions src/graphql/models/YdocVersion.js
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',
},
}),
});
12 changes: 12 additions & 0 deletions src/graphql/queries/GetYdoc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { GraphQLString } from 'graphql';

import Ydoc from 'graphql/models/Ydoc';

export default {
type: Ydoc,
args: {
id: { type: GraphQLString },
},
resolve: async (rootValue, { id }, { loaders }) =>
loaders.docLoader.load({ index: 'ydocs', id }),
};
31 changes: 31 additions & 0 deletions src/graphql/queries/__fixtures__/GetYdoc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
export default {
'/ydocs/doc/foo': {
data: '',
versions: [
{
createdAt: '2020-02-09T15:11:04.472Z',
snapshot: '',
},
{
createdAt: '2020-02-09T15:11:04.472Z',
snapshot: '',
},
{
createdAt: '2020-02-09T15:11:04.472Z',
snapshot: '',
},
{
createdAt: '2020-02-09T15:11:04.472Z',
snapshot: '',
},
],
},
'/articles/doc/foo2': {
data: '',
versions: [],
},
'/articles/doc/foo3': {
data: '',
versions: [],
},
};
26 changes: 26 additions & 0 deletions src/graphql/queries/__tests__/GetYdoc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import gql from 'util/GraphQL';
import { loadFixtures, unloadFixtures } from 'util/fixtures';
import fixtures from '../__fixtures__/GetYdoc';

describe('GetReplyAndGetArticle', () => {
beforeAll(() => loadFixtures(fixtures));

describe('GetYdoc', () => {
it('should get the specified article & associated replies from ID', async () => {
expect(
await gql`
{
GetYdoc(id: "foo") {
data
versions {
createdAt
snapshot
}
}
}
`({}, { user: { id: 'fakeUser', appId: 'LINE' } })
).toMatchSnapshot();
});
});
afterAll(() => unloadFixtures(fixtures));
});
29 changes: 29 additions & 0 deletions src/graphql/queries/__tests__/__snapshots__/GetYdoc.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`GetReplyAndGetArticle GetYdoc should get the specified article & associated replies from ID 1`] = `
Object {
"data": Object {
"GetYdoc": Object {
"data": "",
"versions": Array [
Object {
"createdAt": "2020-02-09T15:11:04.472Z",
"snapshot": "",
},
Object {
"createdAt": "2020-02-09T15:11:04.472Z",
"snapshot": "",
},
Object {
"createdAt": "2020-02-09T15:11:04.472Z",
"snapshot": "",
},
Object {
"createdAt": "2020-02-09T15:11:04.472Z",
"snapshot": "",
},
],
},
},
}
`;
2 changes: 2 additions & 0 deletions src/graphql/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import GetArticle from './queries/GetArticle';
import GetReply from './queries/GetReply';
import GetUser from './queries/GetUser';
import GetCategory from './queries/GetCategory';
import GetYdoc from './queries/GetYdoc';
import ListArticles from './queries/ListArticles';
import ListReplies from './queries/ListReplies';
import ListCategories from './queries/ListCategories';
Expand Down Expand Up @@ -41,6 +42,7 @@ export default new GraphQLSchema({
GetReply,
GetUser,
GetCategory,
GetYdoc,
ListArticles,
ListReplies,
ListCategories,
Expand Down

0 comments on commit e593993

Please sign in to comment.