diff --git a/flow-model-generator/modules/flow-model-generator-core/src/main/java/io/ballerina/flowmodelgenerator/core/TypesManager.java b/flow-model-generator/modules/flow-model-generator-core/src/main/java/io/ballerina/flowmodelgenerator/core/TypesManager.java index 1385e90351..727b6e72db 100644 --- a/flow-model-generator/modules/flow-model-generator-core/src/main/java/io/ballerina/flowmodelgenerator/core/TypesManager.java +++ b/flow-model-generator/modules/flow-model-generator-core/src/main/java/io/ballerina/flowmodelgenerator/core/TypesManager.java @@ -124,6 +124,16 @@ public JsonElement getGraphqlType(SemanticModel semanticModel, Document document if (SyntaxKind.SERVICE_DECLARATION == parentNode.kind()) { optSymbol = semanticModel.symbol(parentNode); } + } else if (SyntaxKind.MARKDOWN_DOCUMENTATION_LINE == node.kind()) { + NonTerminalNode docNode = node.parent(); + if (docNode.kind() == SyntaxKind.MARKDOWN_DOCUMENTATION && + docNode.parent().kind() == SyntaxKind.METADATA) { + MetadataNode metadata = (MetadataNode) docNode.parent(); + NonTerminalNode parentNode = metadata.parent(); + if (SyntaxKind.SERVICE_DECLARATION == parentNode.kind()) { + optSymbol = semanticModel.symbol(parentNode); + } + } } else { optSymbol = semanticModel.symbol(document, linePosition); } diff --git a/flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/types_manager/get_graphql_type/config/get_gql_svc_with_annotation_and_docs.json b/flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/types_manager/get_graphql_type/config/get_gql_svc_with_annotation_and_docs.json new file mode 100644 index 0000000000..0abc5e2e01 --- /dev/null +++ b/flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/types_manager/get_graphql_type/config/get_gql_svc_with_annotation_and_docs.json @@ -0,0 +1,157 @@ +{ + "filePath": "test_pack1/service.bal", + "position": { + "line": 14, + "offset": 0 + }, + "description": "Get service data", + "type": { + "name": "/graphql2", + "editable": true, + "metadata": { + "label": "/graphql2", + "description": "This is a simple GraphQL service that\nincludes a query field." + }, + "codedata": { + "node": "SERVICE_DECLARATION", + "lineRange": { + "fileName": "service.bal", + "startLine": { + "line": 17, + "offset": 0 + }, + "endLine": { + "line": 26, + "offset": 1 + } + } + }, + "properties": { + "name": { + "metadata": { + "label": "Type name", + "description": "Unique name to identify the type" + }, + "valueType": "IDENTIFIER", + "value": "/graphql2", + "optional": false, + "editable": false, + "advanced": false, + "hidden": false + }, + "qualifiers": { + "metadata": { + "label": "Type Qualifiers", + "description": "Qualifiers of the type" + }, + "valueType": "MULTIPLE_SELECT", + "value": [], + "optional": true, + "editable": true, + "advanced": true, + "hidden": false + }, + "isReadOnly": { + "metadata": { + "label": "readonly", + "description": "Is this readonly" + }, + "valueType": "FLAG", + "value": "false", + "optional": true, + "editable": true, + "advanced": false, + "hidden": false + }, + "isArray": { + "metadata": { + "label": "Is array type", + "description": "Is this type an array or list value" + }, + "valueType": "FLAG", + "value": "false", + "optional": true, + "editable": true, + "advanced": true, + "hidden": false + }, + "arraySize": { + "metadata": { + "label": "Size of the array", + "description": "Array dimensions" + }, + "valueType": "STRING", + "value": "", + "optional": false, + "editable": false, + "advanced": false, + "hidden": false + } + }, + "members": [], + "functions": [ + { + "accessor": "get", + "qualifiers": [ + "ISOLATED", + "RESOURCE" + ], + "parameters": [ + { + "kind": "FIELD", + "refs": [], + "type": "string", + "name": "name", + "optional": false, + "readonly": false + } + ], + "kind": "RESOURCE", + "name": "hello", + "description": "Returns a greeting message that includes provided name.", + "returnType": "string", + "refs": [], + "properties": { + "isPrivate": { + "metadata": { + "label": "private", + "description": "Is this private" + }, + "valueType": "FLAG", + "value": "false", + "optional": true, + "editable": true, + "advanced": false, + "hidden": false + }, + "isPublic": { + "metadata": { + "label": "public", + "description": "Is this public" + }, + "valueType": "FLAG", + "value": "false", + "optional": true, + "editable": true, + "advanced": false, + "hidden": false + }, + "isIsolated": { + "metadata": { + "label": "isolated", + "description": "Is this isolated" + }, + "valueType": "FLAG", + "value": "true", + "optional": true, + "editable": true, + "advanced": false, + "hidden": false + } + } + } + ], + "allowAdditionalFields": false + }, + "refs": [] +} diff --git a/flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/types_manager/get_graphql_type/config/get_gql_svc_with_docs.json b/flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/types_manager/get_graphql_type/config/get_gql_svc_with_docs.json new file mode 100644 index 0000000000..e7abcb4942 --- /dev/null +++ b/flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/types_manager/get_graphql_type/config/get_gql_svc_with_docs.json @@ -0,0 +1,157 @@ +{ + "filePath": "test_pack1/service.bal", + "position": { + "line": 2, + "offset": 0 + }, + "description": "Get service data", + "type": { + "name": "/graphql", + "editable": true, + "metadata": { + "label": "/graphql", + "description": "This is a simple GraphQL service that\nincludes a query field." + }, + "codedata": { + "node": "SERVICE_DECLARATION", + "lineRange": { + "fileName": "service.bal", + "startLine": { + "line": 4, + "offset": 0 + }, + "endLine": { + "line": 12, + "offset": 1 + } + } + }, + "properties": { + "name": { + "metadata": { + "label": "Type name", + "description": "Unique name to identify the type" + }, + "valueType": "IDENTIFIER", + "value": "/graphql", + "optional": false, + "editable": false, + "advanced": false, + "hidden": false + }, + "qualifiers": { + "metadata": { + "label": "Type Qualifiers", + "description": "Qualifiers of the type" + }, + "valueType": "MULTIPLE_SELECT", + "value": [], + "optional": true, + "editable": true, + "advanced": true, + "hidden": false + }, + "isReadOnly": { + "metadata": { + "label": "readonly", + "description": "Is this readonly" + }, + "valueType": "FLAG", + "value": "false", + "optional": true, + "editable": true, + "advanced": false, + "hidden": false + }, + "isArray": { + "metadata": { + "label": "Is array type", + "description": "Is this type an array or list value" + }, + "valueType": "FLAG", + "value": "false", + "optional": true, + "editable": true, + "advanced": true, + "hidden": false + }, + "arraySize": { + "metadata": { + "label": "Size of the array", + "description": "Array dimensions" + }, + "valueType": "STRING", + "value": "", + "optional": false, + "editable": false, + "advanced": false, + "hidden": false + } + }, + "members": [], + "functions": [ + { + "accessor": "get", + "qualifiers": [ + "ISOLATED", + "RESOURCE" + ], + "parameters": [ + { + "kind": "FIELD", + "refs": [], + "type": "string", + "name": "name", + "optional": false, + "readonly": false + } + ], + "kind": "RESOURCE", + "name": "hello", + "description": "Returns a greeting message that includes provided name.", + "returnType": "string", + "refs": [], + "properties": { + "isPrivate": { + "metadata": { + "label": "private", + "description": "Is this private" + }, + "valueType": "FLAG", + "value": "false", + "optional": true, + "editable": true, + "advanced": false, + "hidden": false + }, + "isPublic": { + "metadata": { + "label": "public", + "description": "Is this public" + }, + "valueType": "FLAG", + "value": "false", + "optional": true, + "editable": true, + "advanced": false, + "hidden": false + }, + "isIsolated": { + "metadata": { + "label": "isolated", + "description": "Is this isolated" + }, + "valueType": "FLAG", + "value": "true", + "optional": true, + "editable": true, + "advanced": false, + "hidden": false + } + } + } + ], + "allowAdditionalFields": false + }, + "refs": [] +} diff --git a/flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/types_manager/get_graphql_type/source/test_pack1/Ballerina.toml b/flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/types_manager/get_graphql_type/source/test_pack1/Ballerina.toml new file mode 100644 index 0000000000..ed56334e0d --- /dev/null +++ b/flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/types_manager/get_graphql_type/source/test_pack1/Ballerina.toml @@ -0,0 +1,8 @@ +[package] +org = "testorg" +name = "test_pack1" +version = "0.1.0" +distribution = "2201.12.7" + +[build-options] +observabilityIncluded = true diff --git a/flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/types_manager/get_graphql_type/source/test_pack1/service.bal b/flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/types_manager/get_graphql_type/source/test_pack1/service.bal new file mode 100644 index 0000000000..ae12b7778c --- /dev/null +++ b/flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/types_manager/get_graphql_type/source/test_pack1/service.bal @@ -0,0 +1,27 @@ +import ballerina/graphql; + +# This is a simple GraphQL service that +# includes a query field. +service /graphql on new graphql:Listener(9090) { + + # Returns a greeting message that includes provided name. + # + name - Name to be included in the message + # + return - Greeting message with the name + resource function get hello(string name) returns string { + return string `Hello ${name}`; + } +} + +# This is a simple GraphQL service that +# includes a query field. +@graphql:ServiceConfig {maxQueryDepth: 334, auth: []} +service /graphql2 on new graphql:Listener(9091) { + + # Returns a greeting message that includes provided name. + # + name - Name to be included in the message + # + return - Greeting message with the name + @graphql:ResourceConfig {complexity: 5} + resource function get hello(string name) returns string { + return string `Hello ${name}`; + } +}