Gathering detailed insights and metrics for vue-apollo-smart-ops
Gathering detailed insights and metrics for vue-apollo-smart-ops
Gathering detailed insights and metrics for vue-apollo-smart-ops
Gathering detailed insights and metrics for vue-apollo-smart-ops
npm install vue-apollo-smart-ops
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
5 Stars
588 Commits
5 Forks
3 Watching
11 Branches
3 Contributors
Updated on 16 Jul 2024
TypeScript (90.18%)
JavaScript (9.82%)
Cumulative downloads
Total Downloads
Last day
981.8%
119
Compared to previous day
Last week
61.3%
592
Compared to previous week
Last month
-31.8%
2,106
Compared to previous month
Last year
-11.7%
34,709
Compared to previous year
5
32
1
Creates TypeScript-typed operation functions for GraphQL queries and mutations compatible with Vue Apollo.
This library is intended to be used together with the
typescript-vue-apollo-smart-ops
plugin
for GraphQL Code Generator, but it may also be useful standalone.
1npm install --save vue-apollo-smart-ops
createSmartQueryOptionsFunction(query, onError?)
Returns a generated function which returns a Vue Apollo Smart Query options object for the given query when called.
⚠️ Note: The returned function is not meant to execute the query itself. It is only used to configure a Vue Apollo Smart Query. The responsibility for executing the query lies with Vue Apollo.
The returned function accepts an options object as its first argument, allowing variables and other parameters to be customised in runtime usage. Compared with creating an options object directly, the advantage here is that the options accepted by the generated function are fully type-checked based on the query definition - and without needing to pass type arguments at every usage.
Using the @graphql-codegen/typescript-vue-apollo-smart-ops
plugin
you can automatically generate options functions for all the query operations in your project.
The following example manually creates an options function and assigns it to the variable useTodoListQuery
:
1const useTodoListQuery = createSmartQueryOptionsFunction<TodosQuery, TodosQueryVariables>(gql` 2 query Todos($skip: Int, $limit: Int) { 3 todos(skip: $skip, limit: $limit) { 4 id 5 title 6 } 7 } 8`);
This function can subsequently be called inside the apollo
options of a Vue component to configure a Smart Query. The
following example adds a todos
Smart Query to a component, in Vue class component style:
1@Component<TodoList>({ 2 apollo: { 3 todos: useTodoListQuery<TodoList>({ 4 skip() { 5 return this.foo === 'bar'; 6 }, 7 variables() { 8 return { 9 limit: 10, 10 skip: 0, 11 }; 12 }, 13 }), 14 }, 15}) 16class TodoList extends Vue { 17 todos: Todo[] | null = null; 18 19 get foo(): string { 20 return 'bar'; 21 } 22}
@SmartQuery(options)
The @SmartQuery()
decorator works with your generated options functions to enable the declaration of Smart Queries
within the body of a Vue class component, instead of in the component options. This helps to keep the data property and
its query options together in one place.
The following example is equivalent to the previous example but using the decorated syntax style:
1@Component 2class TodoList extends Vue { 3 @SmartQuery( 4 useTodoListQuery<TodoList>({ 5 skip() { 6 return this.foo === 'bar'; 7 }, 8 variables() { 9 return this.vars; 10 }, 11 }), 12 ) 13 todos: Todo[] | null = null; 14 15 get foo(): string { 16 return 'bar'; 17 } 18}
createMutationFunction(mutation, onError?)
Returns a generated function which executes a mutation and returns the result when called.
The returned function requires a Vue app instance as its first argument (from which the $apollo
client will be
accessed), and accepts an options object as its second argument, allowing variables and other parameters to be
customised in runtime usage. Compared with executing a mutation using the Vue Apollo client directly, the advantage here
is that the options accepted by the generated function are fully type-checked based on the operation definition - and
without needing to pass type arguments at every usage.
Using the @graphql-codegen/typescript-vue-apollo-smart-ops
plugin
you can automatically generate mutation functions for all the mutation operations in your project.
The following example manually creates a mutation function and assigns it to the variable todoCreateMutation
:
1const todoCreateMutation = createMutationFunction<TodoCreateMutation, TodoCreateMutationVariables>(gql` 2 mutation TodoCreate($input: TodoInput!) { 3 todoCreate(input: $input) { 4 todo { 5 id 6 title 7 } 8 } 9 } 10`);
The following example demonstrates how to call this mutation from a method on a component:
1@Component 2class TodoList extends Vue { 3 async onClickCreateTodoButton(): Promise<void> { 4 const result = await todoCreateMutation(this, { 5 variables: { 6 title: 'Bake a cake', 7 }, 8 }); 9 10 if (!result.success) { 11 throw new Error(`Failed to create Todo!`); 12 } 13 } 14}
@SmartQuery()
decorator is based on the vue-apollo-decorator
package by chanlito, with some alteration to the types.No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
9 existing vulnerabilities detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
license file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More