Skip to content

Commit

Permalink
Added initial setup for fill fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
imolorhe committed Mar 16, 2019
1 parent ea450ad commit 82e9db7
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ export class DocViewerComponent implements OnChanges {
*/
goHome() {
this.setDocViewChange.next({ view: 'root' });
this.docHistory = [];
}

/**
Expand Down
21 changes: 21 additions & 0 deletions src/app/components/query-editor/query-editor.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ export class QueryEditorComponent implements OnInit, AfterViewInit, OnChanges {

// show current token parent type in docs
'Ctrl-D': cm => this.onShowInDocsByToken(cm),

'Shift-Ctrl-Enter': cm => this.onFillFields(cm),
},
gutters: ['CodeMirror-linenumbers', 'CodeMirror-foldgutter'],
autoCloseBrackets: true,
Expand Down Expand Up @@ -220,6 +222,25 @@ export class QueryEditorComponent implements OnInit, AfterViewInit, OnChanges {
}
}

onFillFields(cm) {
const cursor = cm.getCursor();
const token = cm.getTokenAt(cursor);
const typeInfo = getTypeInfo(this.gqlSchema, token.state);

const schema = this.gqlSchema;
if (!schema) {
return;
}

const rawResults = this.gqlService.getAutocompleteSuggestions(
schema,
cm.getValue(),
cursor,
token,
);
// console.log(token, typeInfo, rawResults);
}

/**
* Update the editor schema
* @param schema
Expand Down
16 changes: 15 additions & 1 deletion src/app/services/gql/gql.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,17 @@ import * as prettierGraphql from 'prettier/parser-graphql';

import { SubscriptionClient, ClientOptions as SubscriptionClientOptions } from 'subscriptions-transport-ws';
// TODO: Use `getIntrospectionQuery` instead of `introspectionQuery` when there is typings for it
import { buildClientSchema, parse, print, GraphQLSchema, printSchema, getIntrospectionQuery, validateSchema, visit } from 'graphql';
import {
buildClientSchema,
parse,
print,
GraphQLSchema,
printSchema,
getIntrospectionQuery,
validateSchema,
visit
} from 'graphql';
import { getAutocompleteSuggestions } from 'graphql-language-service-interface';
import * as compress from 'graphql-query-compress'; // Somehow this is the way to use this

import { NotifyService } from '../notify/notify.service';
Expand Down Expand Up @@ -257,6 +267,10 @@ export class GqlService {
}
}

getAutocompleteSuggestions(...args) {
return getAutocompleteSuggestions(...args);
}

parseQuery(query: string) {
if (!query) {
return {};
Expand Down

0 comments on commit 82e9db7

Please sign in to comment.