import { Ref } from "@nuxtjs/composition-api" import { GraphQLSchema } from "graphql" import { getAutocompleteSuggestions } from "graphql-language-service-interface" import { Completer, CompleterResult, CompletionEntry } from "." const completer: (schemaRef: Ref) => Completer = (schemaRef: Ref) => (text, completePos) => { if (!schemaRef.value) return Promise.resolve(null) const completions = getAutocompleteSuggestions(schemaRef.value, text, { line: completePos.line, character: completePos.ch, } as any) return Promise.resolve({ completions: completions.map( (x, i) => { text: x.label!, meta: x.detail!, score: completions.length - i, } ), }) } export default completer