Add GraphQL support: foundation and catalog query resolvers#14
Open
devin-ai-integration[bot] wants to merge 7 commits intodevelop-7.0.xfrom
Open
Add GraphQL support: foundation and catalog query resolvers#14devin-ai-integration[bot] wants to merge 7 commits intodevelop-7.0.xfrom
devin-ai-integration[bot] wants to merge 7 commits intodevelop-7.0.xfrom
Conversation
Co-Authored-By: Arjun Mishra <arjunsaxmishra@gmail.com>
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
…rror messages Co-Authored-By: Arjun Mishra <arjunsaxmishra@gmail.com>
… args Co-Authored-By: Arjun Mishra <arjunsaxmishra@gmail.com>
Co-Authored-By: Arjun Mishra <arjunsaxmishra@gmail.com>
…solver Co-Authored-By: Arjun Mishra <arjunsaxmishra@gmail.com>
…ed search offsets Co-Authored-By: Arjun Mishra <arjunsaxmishra@gmail.com>
…text to avoid overwriting resolved customer Co-Authored-By: Arjun Mishra <arjunsaxmishra@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Introduces initial GraphQL support in
broadleaf-framework-web, covering both the shared infrastructure (Ticket 1) and catalog-side query/field resolvers (Ticket 2). Existing REST controllers are untouched.What's in this PR
Dependencies
spring-boot-starter-graphqltocore/broadleaf-framework-web/pom.xmland the root<dependencyManagement>.org.reactivestreams:reactive-streamsto1.0.4and excludes the transitive1.0.3pulled in bygraphql-java/java-dataloaderto satisfy the enforcer'sDependencyConvergencerule.Foundation (
org.broadleafcommerce.core.web.graphql)GraphQLContextInterceptor—WebGraphQlInterceptorthat resolves acustomerIdfrom thecustomerIdheader or query parameter, loads the customer viaCustomerService, and populatesCustomerState. Falls back to an anonymouscustomerService.createCustomer()when no identity is provided (mirroringRestApiCustomerStateFilter).GraphQLExceptionResolver— extendsDataFetcherExceptionResolverAdapterand mapsAddToCartException,PricingException,OfferMaxUseExceededException,IllegalCartOperationException,RemoveFromCartException,UpdateCartExceptionto stableerrorCodevalues in the errorextensions; everything else becomesINTERNAL_ERROR.src/main/resources/graphql/schema.graphqls— schema forQuery,Mutation,Product,Category,Sku,ProductOption/ProductOptionValue,Order/OrderItem/OrderItemAttribute,FulfillmentGroup/FulfillmentGroupItem,Address,OrderPayment,Customer, aMoneyobject type, aBigDecimalscalar, and input types for cart/shipping/billing.src/main/resources/graphql-application.properties— setsspring.graphql.graphiql.enabled,spring.graphql.path=/graphql, andspring.graphql.schema.locations=classpath:graphql/.Resolvers (
org.broadleafcommerce.core.web.graphql.resolvers)CatalogQueryResolver—@QueryMappingmethods forproduct,productByExternalId,productByUri,products,category,categoryByUri,categories,sku,skuByUpc, delegating toCatalogService.SearchQueryResolver—searchquery builds aSearchCriteria(query, pageSize, startIndex, derived page) and callsSearchService.findSearchResults.CategoryFieldResolver— lazy@SchemaMappingforCategory.activeSubCategoriesandCategory.products.ProductFieldResolver— lazy@SchemaMappingforProduct.defaultCategory,defaultSku,additionalSkus,productOptions.SkuFieldResolver—@SchemaMappingforSku.salePrice,retailPrice,costreturning BroadleafMoney, plusMoney.currencymappingCurrencyto its ISO code.Verification
mvn compile -pl core/broadleaf-framework-web -am -q -DskipTestspasses locally.Things worth a careful look
graphql-application.propertiesis not auto-imported. Spring Boot only loadsapplication.properties/application.ymlautomatically. Becausebroadleaf-framework-webis a library, downstream apps will need tospring.config.import=classpath:graphql-application.properties(or equivalent) for these settings to take effect. Confirm this matches the intended consumption model.BigDecimalscalar is declared in the schema but no scalar is wired in code.graphql-javadoes not ship aBigDecimalscalar by default, so schema initialization could fail at runtime in an app that actually boots this. If the intent is to rely ongraphql-java-extended-scalars, that dependency is not added here; happy to follow up in this PR if desired.customerService.createCustomer()writes a newCustomeron every request that lacks acustomerId. This matchesRestApiCustomerStateFilter, but worth confirming it's the right behavior for a public, potentially high-traffic GraphQL endpoint.CustomerState.CartStateis left to whatever downstream filters/refreshers handle it. Flag if you want cart context explicitly populated in the interceptor.SearchQueryResolverswallows exceptions and returns an empty list (logged at WARN). This avoids turning search infrastructure failures into GraphQL errors, but it also hides them from clients. Let me know if you'd prefer these surface throughGraphQLExceptionResolverinstead.reactive-streamsexclusion + pin was the minimal change to pass the enforcer. Worth a sanity check that no other module relied on the old1.0.3coming in via graphql's transitive path (reactor-core already brings1.0.4, so this should be a no-op outside graphql).Labels / Milestone
Link to Devin session: https://app.devin.ai/sessions/15e5916b1b97406aae75ee8d5aa99700
Requested by: @Colhodm