abstracting generic type resolving

This commit is contained in:
Samuel Andert 2023-08-23 12:23:50 +02:00
parent 019593a4a1
commit 39e1f2afbc
2 changed files with 113 additions and 11 deletions

View File

@ -48,23 +48,30 @@ const client = createClient({
},
});
const finalQuery = `
const generateSubscriptionQuery = (typeName) => {
const typeDefinition = findTypeDefinition(typeName);
const fields = extractFields(typeDefinition);
return `
subscription {
projects_mutated {
${typeName}_mutated {
key
event
data {
${projectsFields}
${fields}
}
}
}
`;
};
console.log(finalQuery);
// Generate subscription query for 'projects'
const projectsQuery = generateSubscriptionQuery('projects');
// const todosQuery = generateSubscriptionQuery('todos');
client.subscribe(
{
query: finalQuery,
query: projectsQuery,
},
{
next: data => {

View File

@ -2,20 +2,31 @@ type Query {
projects(filter: projects_filter, sort: [String], limit: Int, offset: Int, page: Int, search: String): [projects!]!
projects_by_id(id: ID!): projects
projects_aggregated(groupBy: [String], filter: projects_filter, limit: Int, offset: Int, page: Int, search: String, sort: [String]): [projects_aggregated!]!
todos(filter: todos_filter, sort: [String], limit: Int, offset: Int, page: Int, search: String): [todos!]!
todos_by_id(id: ID!): todos
todos_aggregated(groupBy: [String], filter: todos_filter, limit: Int, offset: Int, page: Int, search: String, sort: [String]): [todos_aggregated!]!
}
type Mutation {
create_projects_items(filter: projects_filter, sort: [String], limit: Int, offset: Int, page: Int, search: String, data: [create_projects_input!]): [projects!]!
create_projects_item(data: create_projects_input!): projects
create_todos_items(filter: todos_filter, sort: [String], limit: Int, offset: Int, page: Int, search: String, data: [create_todos_input!]): [todos!]!
create_todos_item(data: create_todos_input!): todos
update_projects_items(filter: projects_filter, sort: [String], limit: Int, offset: Int, page: Int, search: String, ids: [ID]!, data: update_projects_input!): [projects!]!
update_projects_batch(filter: projects_filter, sort: [String], limit: Int, offset: Int, page: Int, search: String, data: [update_projects_input!]): [projects!]!
update_projects_item(id: ID!, data: update_projects_input!): projects
update_todos_items(filter: todos_filter, sort: [String], limit: Int, offset: Int, page: Int, search: String, ids: [ID]!, data: update_todos_input!): [todos!]!
update_todos_batch(filter: todos_filter, sort: [String], limit: Int, offset: Int, page: Int, search: String, data: [update_todos_input!]): [todos!]!
update_todos_item(id: ID!, data: update_todos_input!): todos
delete_projects_items(ids: [ID]!): delete_many
delete_projects_item(id: ID!): delete_one
delete_todos_items(ids: [ID]!): delete_many
delete_todos_item(id: ID!): delete_one
}
type Subscription {
projects_mutated(event: EventEnum): projects_mutated
todos_mutated(event: EventEnum): todos_mutated
directus_dashboards_mutated(event: EventEnum): directus_dashboards_mutated
directus_activity_mutated(event: EventEnum): directus_activity_mutated
directus_notifications_mutated(event: EventEnum): directus_notifications_mutated
@ -544,6 +555,53 @@ type projects_mutated {
data: projects
}
type todos {
id: ID!
status: String
sort: Int
user_created(filter: directus_users_filter, sort: [String], limit: Int, offset: Int, page: Int, search: String): directus_users
date_created: Date
date_created_func: datetime_functions
user_updated(filter: directus_users_filter, sort: [String], limit: Int, offset: Int, page: Int, search: String): directus_users
date_updated: Date
date_updated_func: datetime_functions
task: String
}
type todos_aggregated {
group: JSON
countAll: Int
count: todos_aggregated_count
countDistinct: todos_aggregated_count
avg: todos_aggregated_fields
sum: todos_aggregated_fields
avgDistinct: todos_aggregated_fields
sumDistinct: todos_aggregated_fields
min: todos_aggregated_fields
max: todos_aggregated_fields
}
type todos_aggregated_count {
id: Int
status: Int
sort: Int
user_created: Int
date_created: Int
user_updated: Int
date_updated: Int
task: Int
}
type todos_aggregated_fields {
sort: Float
}
type todos_mutated {
key: ID!
event: EventEnum
data: todos
}
input boolean_filter_operators {
_eq: Boolean
_neq: Boolean
@ -632,6 +690,17 @@ input create_projects_input {
text: String
}
input create_todos_input {
id: ID
status: String
sort: Int
user_created: create_directus_users_input
date_created: Date
user_updated: create_directus_users_input
date_updated: Date
task: String
}
input date_filter_operators {
_eq: String
_neq: String
@ -908,6 +977,21 @@ input string_filter_operators {
_nempty: Boolean
}
input todos_filter {
id: string_filter_operators
status: string_filter_operators
sort: number_filter_operators
user_created: directus_users_filter
date_created: date_filter_operators
date_created_func: datetime_function_filter_operators
user_updated: directus_users_filter
date_updated: date_filter_operators
date_updated_func: datetime_function_filter_operators
task: string_filter_operators
_and: [todos_filter]
_or: [todos_filter]
}
input update_directus_files_input {
id: ID
storage: String
@ -984,3 +1068,14 @@ input update_projects_input {
date_updated: Date
text: String
}
input update_todos_input {
id: ID
status: String
sort: Int
user_created: update_directus_users_input
date_created: Date
user_updated: update_directus_users_input
date_updated: Date
task: String
}