Skip to content

Commit

Permalink
feat(YDoc): implement GetYdoc query and Ydoc model
Browse files Browse the repository at this point in the history
  • Loading branch information
nonumpa committed Sep 7, 2023
1 parent f98df43 commit 3b8d566
Show file tree
Hide file tree
Showing 4 changed files with 46 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 }),
};
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 3b8d566

Please sign in to comment.