-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.vue
67 lines (56 loc) · 1.68 KB
/
app.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<template>
<div>
<NuxtExampleLayout
repo="diizzayy/nuxt-graphql-client"
example="subscription"
class="text-start"
>
<!-- <template #name>
<NuxtLink to="https://github.com/Diizzayy/nuxt-graphql-client/tree/refactor/ohmygql/examples/subscription">
subscription
</NuxtLink>
</template> -->
<div grid grid-cols-2>
<div>
<div>
<p>WS Status: {{ wsStatus }}</p>
</div>
<div v-if="wsStatus === 'connected'">
<p id="connected">🟩</p>
</div>
<div>
<input id="todoInput" v-model="todoInput" type="text" />
</div>
<NButton @click="createTodo()"> Create Todo </NButton>
</div>
<div id="todoResponse">
{{ data }}
</div>
</div>
</NuxtExampleLayout>
</div>
</template>
<script lang="ts" setup>
import type { TodoAddedSubscription } from '#gql';
const wsStatus = ref<string>('');
const todoInput = ref(`Random Text ${Math.random().toString()}`);
const data = ref<TodoAddedSubscription['todoAdded'] | null>(null);
onMounted(() => {
const { subscribe, onResult, onError, unsubscribe } = GqlTodoAdded(null, {
on: {
opened: () => (wsStatus.value = 'opened'),
connected: () => (wsStatus.value = 'connected'),
connecting: () => (wsStatus.value = 'connecting'),
closed: () => (wsStatus.value = 'closed'),
},
});
if (onResult) {
console.log('onResult', onResult);
// onResult((result) => {
// data.value = result.data?.todoAdded
// })
}
subscribe();
});
const createTodo = () => GqlCreateTodo({ todo: { text: todoInput.value } });
</script>