Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing descriptions and add more hover information for arguments #515

Merged
merged 1 commit into from
Jul 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions packages/apollo-language-server/src/languageProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,27 +197,31 @@ export class GraphQLLanguageProvider {
}
break;
}

case Kind.FIELD: {
const parentType = typeInfo.getParentType();
const fieldDef = typeInfo.getFieldDef();

if (parentType && fieldDef) {
const argsString = fieldDef.args.length > 0 ?
`(${fieldDef.args.map(a => `${a.name}: ${a.type}`).join(", ")})` : "";
return {
contents: `
\`\`\`graphql
${parentType}.${fieldDef.name}: ${fieldDef.type}
${parentType}.${fieldDef.name}${argsString}: ${fieldDef.type}
\`\`\`
${fieldDef.description}
`,
range: rangeForASTNode(highlightNodeForNode(node))
};
}

break;
}
case Kind.NAMED_TYPE: {
const type = typeInfo.getType() as GraphQLNamedType | void;

if (!(type && type.astNode && type.astNode.loc)) break;
case Kind.NAMED_TYPE: {
const type = set.schema.getType(node.name.value) as GraphQLNamedType | void;
if (!type) break;

return {
contents: `
Expand All @@ -229,6 +233,19 @@ ${type.description}
range: rangeForASTNode(highlightNodeForNode(node))
};
}

case Kind.ARGUMENT: {
const argumentNode = typeInfo.getArgument()!;
return {
contents: `
\`\`\`graphql
${argumentNode.name}: ${argumentNode.type}
\`\`\`
${argumentNode.description}
`,
range: rangeForASTNode(highlightNodeForNode(node))
}
}
}
}
return null;
Expand Down
4 changes: 1 addition & 3 deletions packages/apollo-language-server/src/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,7 @@ export class GraphQLProject {

for (const set of this.documentSets) {
if (!set.schema!.getQueryType()!.astNode) {
const schemaSource = printSchema(set.schema!, {
commentDescriptions: true
});
const schemaSource = printSchema(set.schema!);

set.schema = buildSchema(
new Source(
Expand Down
26 changes: 19 additions & 7 deletions packages/apollo-vscode/syntaxes/graphql.json
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,25 @@
]
},
"graphql-comment": {
"comment":
"need to prefix comment space with a scope else Atom's reflow cmd doesn't work",
"name": "comment.line.graphql.js",
"match": "(\\s*)(#).*",
"captures": {
"1": { "name": "punctuation.whitespace.comment.leading.graphql" }
}
"patterns": [
{
"comment":
"need to prefix comment space with a scope else Atom's reflow cmd doesn't work",
"name": "comment.line.graphql.js",
"match": "(\\s*)(#).*",
"captures": {
"1": { "name": "punctuation.whitespace.comment.leading.graphql" }
}
},
{
"name": "comment.line.graphql.js",
"begin": "(\"\"\")",
"end": "(\"\"\")",
"beginCaptures": {
"1": { "name": "punctuation.whitespace.comment.leading.graphql" }
}
}
]
},
"graphql-variable-definitions": {
"begin": "\\s*(\\()",
Expand Down