friatech / lilo

Lilo is a super-fast, easy-to-use, configurable GraphQL stitching library
Apache License 2.0
38 stars 3 forks source link

Namespace concept as in Braid #19

Open ShibyNiju opened 1 year ago

ShibyNiju commented 1 year ago

In braid, there is a namespace concept. This will make possible to define graphql query with same name to be created in different microservices. Similarly, the schema in lilo should also considered while merging the graphql queries from different microservices. Now a duplicate exception occurs if there are similar named queries in different microservices while merging the schema

firatkucuk commented 1 year ago

Hello, can you provide a very basic example? you can modify the basic example in our samples directory, So we can add support of namespaces. Thanks for the good feedback.

ShibyNiju commented 1 year ago

Shall i quote the example here? Microservice 1 - user1 - user_get Microservice 2 - user2 - user_get

So when merging Microservice 1 and Microservice 2 with schema names user1 and user2 respectively, now error occurs. Schema name can be used as a namespace and store the 2 queries in the merged schema.

firatkucuk commented 1 year ago

Ok. I'll examine it and get back to you. Thanks.

firatkucuk commented 1 year ago

Ok, I want to learn about your practical usage about this. I have tried with Atlassian braid.

        final String graphqlTypeDefinition = "type Query {\n" +
            "    user_get: String!\n" +
            "}\n";

        final Braid braid = Braid.builder()
            .schemaSource(QueryExecutorSchemaSource.builder()
                .namespace(SchemaNamespace.of("namespace1"))
                .schemaLoader(new StringSchemaLoader(SchemaLoader.Type.IDL, graphqlTypeDefinition))
                .localRetriever(new Function<Query, Object>() {
                    @Override
                    public Object apply(final Query query) {
                        return ImmutableMap.of("user_get1100", "admin");
                    }
                })
                .build())
            .schemaSource(QueryExecutorSchemaSource.builder()
                .namespace(SchemaNamespace.of("namespace2"))
                .schemaLoader(new StringSchemaLoader(SchemaLoader.Type.IDL, graphqlTypeDefinition))
                .localRetriever(new Function<Query, Object>() {
                    @Override
                    public Object apply(final Query query) {
                        return ImmutableMap.of("user_get1100", "user");
                    }
                })
                .build())
            .build();

        String query = "{user_get}";

        final ExecutionResult result = braid.newGraphQL().execute(newExecutionInput().query(query).build()).join();

and getting java.lang.IllegalStateException: Duplicate key Query.user_get error. For such scenario what are your type definitions and what is your query?