/* import Vue from 'vue'

import { ref } from '@vue/composition-api'
import gql from 'graphql-tag'

import { graphQL } from '@/graphql'

export const useGraphQL = (props, context, queries = []) => {
  const data = {}

  const connected = ref(graphQL.link?.client?.readyState === 1)

  graphQL.link.on('connecting', () => { connected.value = false })
  graphQL.link.on('connected', () => { connected.value = true })
  graphQL.link.on('reconnecting', () => { connected.value = false })
  graphQL.link.on('reconnected', () => { connected.value = true })
  graphQL.link.on('disconnected', () => { connected.value = false })
  graphQL.link.on('error', () => { connected.value = false })

  const login = async (email, passwort) => {
    let query = `login(email: "${email}", passwort: "${passwort}")`
    if (!email || !passwort) {
      query = `login(token: "${Vue.$cookies.get('token')}")`
    }

    const { data } = await graphQL.mutate({
      mutation: gql`mutation { ${query} {
        _id vorname nachname token
        acl {
          master { master von bis }
          verein { _id von bis _verein { name } }
          mannschaft { _id von bis _mannschaft { name } _verein { name } }
        }
      }}`,
    })

    context.root.$store.commit('SET_PROFILE', data.login)

    Vue.$cookies.set('token', data?.login?.token, '12h', null, null, null, 'strict')
  }

  const query = async (q) => {
    const coll = q.split(/ |{|\(/)[0]
    const response = await graphQL.query({
      query: gql`query { ${q} }`,
    })

    return response?.data?.[coll]
  }

  const mutate = async (q) => {
    const coll = q.split(/ |{|\(/)[0]
    const response = await graphQL.mutate({
      mutation: gql`mutation { ${q} }`,
    })

    return response?.data?.[coll]
  }

  const subscribe = async (q, cb) => {
    if (typeof cb !== 'function') return null

    const coll = q.split(/ |{|\(/)[0]
    return graphQL.subscribe({
      query: gql`subscription { ${q} }`,
    }).subscribe({
      next: (response) => {
        cb(response.data[coll])
      },
    })
  }

  return { ...data, connected, login, query, mutate, subscribe }
} */
