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

Generate GraphQL schema for local service variable declaration #3317

Closed
MohamedSabthar opened this issue Sep 6, 2022 · 8 comments · Fixed by ballerina-platform/module-ballerina-graphql#1704
Labels
module/graphql Issues related to Ballerina GraphQL module Status/Blocked Issues that are currently blocked. Team/PCM Protocol connector packages related issues Type/Improvement

Comments

@MohamedSabthar
Copy link
Member

Description:
The current implementation of graphql module generate schema for both service declaration and module level (graphql:Service) variable declaration. But it not yet generates graphql schema for local variable declaration.

ex: bellow code doesn't generate a schema

import ballerina/lang.runtime;
import ballerina/graphql;

public function main() returns error? {
    // local service variable declaration
    graphql:Service backendService = service object {
        resource function get greeting() returns string {
            return "Hello, World";
        }
    };
    
    graphql:Listener serverEP = check new(4000);
    check serverEP.attach(backendService, "graphql");
    check serverEP.'start();
    runtime:registerListener(serverEP);
}

Ideally graphql module should generate schema for local variable declaration in any block scope (function definition, if else body, object field, and so on)

Describe your problem(s)

Describe your solution(s)

Related Issues (optional):

Suggested Labels (optional):

Suggested Assignees (optional):

@MohamedSabthar MohamedSabthar added Type/Improvement module/graphql Issues related to Ballerina GraphQL module Team/PCM Protocol connector packages related issues labels Sep 6, 2022
@MohamedSabthar
Copy link
Member Author

MohamedSabthar commented Sep 7, 2022

The graphql schema is generated in compile time and attached as a field of @graphql:ServiceConfig annotation of the graphql service object/declaration.

This is done by the graphql compiler plugin by following two steps
Step 1, the service object Nodes are collected in Map (by a SyntaxNodeAnaylysisTask)
In step 2, the collected Nodes are modified (by a SourceModiferTask)
Finally, The generated schema is accessed in runtime from the annotation to run the service.

In the Second task, the node modification is performed by traversing the ModulePartNode (of the document) in a top-down manner. If the service node collected in the Map (from step 1) is found during the traversal then the node is modified with the annotation and the parent nodes are recursively modified until it reaches the ModulePartNode.

The schema generation for module-level service variable declaration and service declaration already implemented using the mentioned approach. But it’s not efficient to implement the local service variable declaration as we need to consider a lot of local scopes (function definition, if else body, object field, etc...).
A simpler way to replace the node from the tree is required.

@MaryamZi @hasithaa @warunalakshitha is there a simpler compiler plugin API to achieve this ?

@MohamedSabthar
Copy link
Member Author

MohamedSabthar commented Sep 7, 2022

+@shafreenAnfar

@hasithaa
Copy link

hasithaa commented Sep 8, 2022

@MohamedSabthar Could you point me to the implementation of SyntaxNodeAnaylysisTask and SourceModiferTask.

One way to achieve this is you could listen to object contractor events and add those to the map. Then later annotate it with graphql:ServiceConfig using SourceModiferTask.

@MohamedSabthar
Copy link
Member Author

MohamedSabthar commented Sep 8, 2022

@MohamedSabthar Could you point me to the implementation of SyntaxNodeAnaylysisTask and SourceModiferTask.

@hasithaa these are the implementation SyntaxNodeAnaylysisTask, SourceModifierTask

@MohamedSabthar
Copy link
Member Author

Had a chat with @hasithaa @azinneera @ThisaruGuruge and @DimuthuMadushan on this issue.
A new feature is requested #38054

@MohamedSabthar
Copy link
Member Author

Blocked on #38054

@MohamedSabthar MohamedSabthar added the Status/Blocked Issues that are currently blocked. label Oct 4, 2022
@hasithaa
Copy link

hasithaa commented Oct 4, 2022

@MohamedSabthar Shall we try to implement this with current design as we discussed during the call. Main problem with current design is not scalable when we have multiple code modifiers/modifications.

@MohamedSabthar
Copy link
Member Author

Since there is low ROI, involves complex logic, and there's no urgency of this feature, the implementation of this functionality put on hold

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module/graphql Issues related to Ballerina GraphQL module Status/Blocked Issues that are currently blocked. Team/PCM Protocol connector packages related issues Type/Improvement
Projects
Archived in project
2 participants