gqlQuery.ts 868 B

123456789101112131415161718192021222324252627
  1. import { Ref } from "@nuxtjs/composition-api"
  2. import { GraphQLSchema } from "graphql"
  3. import { getAutocompleteSuggestions } from "graphql-language-service-interface"
  4. import { Completer, CompleterResult, CompletionEntry } from "."
  5. const completer: (schemaRef: Ref<GraphQLSchema | null>) => Completer =
  6. (schemaRef: Ref<GraphQLSchema | null>) => (text, completePos) => {
  7. if (!schemaRef.value) return Promise.resolve(null)
  8. const completions = getAutocompleteSuggestions(schemaRef.value, text, {
  9. line: completePos.line,
  10. character: completePos.ch,
  11. } as any)
  12. return Promise.resolve(<CompleterResult>{
  13. completions: completions.map(
  14. (x, i) =>
  15. <CompletionEntry>{
  16. text: x.label!,
  17. meta: x.detail!,
  18. score: completions.length - i,
  19. }
  20. ),
  21. })
  22. }
  23. export default completer