Coder Social home page Coder Social logo

wp-graphql / wp-graphql-woocommerce Goto Github PK

View Code? Open in Web Editor NEW
625.0 18.0 121.0 5.65 MB

Add WooCommerce support and functionality to your WPGraphQL server

Home Page: https://woographql.com

License: GNU General Public License v3.0

Shell 0.94% PHP 98.86% Dockerfile 0.21%
graphql woocommerce wp-plugin wordpress-plugin wp-graphql graphql-server api mutations wp-graphql-woocommerce hacktoberfest

wp-graphql-woocommerce's Introduction

WPGraphQL WooCommerce (WooGraphQL) Logo

WPGraphQL WooCommerce (WooGraphQL)

WebsiteDocsSchemaPlaygroundAbout • Join Slack

Automated-Testing Coding-Standards Coverage Status Financial Contributors on Open Collective

Install

Installing Manually

  1. Install and activate WPGraphQL and WooCommerce.
  2. Download the wp-graphql-woocommerce.zip file from the Assets section of the most stable release and activate the plugin in your WordPress directory.
  3. Set your GraphQL client endpoint to your site's GraphQL endpoint. Typically, this is your-store.domain/graphql.

Installing with Composer

This method is recommended for users with unique installations like WP Bedrock or SpinupWP.

  1. Install WordPress and WooCommerce.
  2. Install WPGraphQL and WooGraphQL by running composer require wp-graphql/wp-graphql wp-graphql/wp-graphql-woocommerce.
  3. Set your GraphQL client endpoint to your site's GraphQL endpoint. For typical Bedrock or SpinupWP setups, the default will be your-store.domain/wp/graphql.

Optional Extras

  • Install & activate WPGraphQL-JWT-Authentication to introduce a login mutation that returns a JSON Web Token.
  • Install & activate WPGraphQL Headless Login to introduce a login mutation with OAuth2 client support. Shouldn't be used with WPGraphQL-JWT-Authentication
  • Install & activate WPGraphQL-CORS for enhanced security via HTTP CORS and to utilize some advanced WPGraphQL features.

What Can You Do with This Extension?

  • Query your shop's products and variations with detailed filtering options.
  • Query customers, orders, coupons, and refunds. Note: Operations have user restrictions.
  • Manage customer sessions using JWTs, and use cart/customer queries and mutations. Note: Operations have user restrictions.
  • Manually create orders, automate order creation with the checkout mutation, or delegate a customer's session to the WooCommerce checkout page in your theme for comprehensive payment gateway support.

(*) These operations have user restrictions. Learn how to utilize them correctly at the resources listed below:

(#) The recommended method to checkout, taking full advantage of WooCommerce's payment gateways for payment process and other checkout-related extenstions, is to pass the session back to the WordPress installation and let WooCommerce take over from the tradition checkout page. Learn more about this approach below.

Alternatively, you can create a custom checkout form and process payments externally. Here is some resources for that as well.

Why Don't WooCommerce CPT GraphQL Types Support All the Features WPGraphQL Exposes for Most WordPress CPTs?

WooCommerce's Custom Post Types (CPTs) and most data objects are managed by a data store system. This system allows for flexible data object definitions. While objects like products, orders, and coupons are defined as WordPress CPTs by default, they don't have to be.

This flexibility also lets WooCommerce store metadata for these CPTs in separate tables, and the data doesn't necessarily have to reside in the same database.

The data store system and its object managers are WooGraphQL's primary contact points. Unlike standard CPTs, which use a WP_Post object for data sourcing and a WPGraphQL\Model\Post object for modeling, WooGraphQL engages object managers for its data source. Each object type has a unique model with distinct permissions and restrictions.

Such a setup has resulted in some disparities between the schema where WooGraphQL support might be lacking. We apologize for any inconvenience. Both I and the entire WPGraphQL team are actively working to harmonize WooGraphQL with all WPGraphQL and WPGraphQL ACF features.

Thank you for your patience 😄 @kidunot89

Future Features

  • Product CRUD mutations.
  • And some other stuff I'm sure 🤔

For WooCommerce Extensions Support

WooGraphQL Pro is an extension of WPGraphQL WooCommerce that provides compatibility with a variety of popular WooCommerce extensions. This compatibility empowers you to leverage these extensions within the context of the GraphQL API, thereby enabling you to build more dynamic and powerful headless eCommerce applications.

The following WooCommerce extensions are supported by WooGraphQL Pro:

  • WooCommerce Subscriptions
  • WooCommerce Product Bundles
  • WooCommerce Product Add-Ons
  • WooCommerce Composite Products

Installing Supported WooCommerce Extensions (Optional)

If you wish to use any of the supported WooCommerce extensions with WooGraphQL Pro, follow these steps:

  1. Purchase your desired extensions from the WooCommerce marketplace. The supported extensions are listed above.
  2. Download the .zip file(s) for your purchased extension(s) from your WooCommerce account.
  3. In your WordPress Admin Dashboard, navigate to Plugins > Add New > Upload Plugin, and upload the downloaded .zip file(s).
  4. Once the upload is complete, click on 'Activate Plugin' to activate the extension(s).

Installing and Activating WooGraphQL Pro

To install and activate WooGraphQL Pro, follow these steps:

  1. Purchase WooGraphQL Pro from our official website.
  2. After purchase you should find yourself on your account dashboard. Go to the Licenses page and generate and new license and copy it for later.
  3. Next go to the Downloads page and download the latest version of WooGraphQL Pro.
  4. Go to your WordPress Admin Dashboard, navigate to Plugins > Add New > Upload Plugin, and upload the woographql-pro.zip file you downloaded.
  5. After uploading, click 'Activate Plugin' to activate WooGraphQL Pro.

Enabling Schema Support for Installed Extensions

To enable schema support for your installed extensions, follow these steps:

  1. Navigate to the WPGraphQL settings page on your WordPress Admin Dashboard.
  2. Click on the 'WooGraphQL' tab.
  3. Here, you'll find a list of WooGraphQL configuration options. Go below to the WooGraphQL Pro section and paste in license and check the boxes next to your installed extensions to enable schema support for them.

Note: The 'Enable Unsupported Product Type' option can be found on the same settings tab. If you enable this option, any product type without a proper GraphQL type will default to the UnsupportedProduct type, which is identical to the SimpleProduct type. With this type, the client can use the metaData field to get a string representation of the meta data on the type. This could potentially be all that's needed for simpler product types.

With WooGraphQL Pro and your chosen extensions now installed, you're ready to build more sophisticated, feature-rich eCommerce solutions with WordPress and WooCommerce.

Development Tools

Playground

Feel free to test out the extension using this GraphiQL Playground. The playground allows you to execute queries and mutations, as well as view the schema (*).

(*) I have a tendency to forget to update the playground between releases 😅, so if you believe this to be the case look me up somewhere on this page and lemme know 🤷‍♂️

create-woonext-app CLI and @woographql packages

Designed to both streamline development for individuals and teams looking to utilize WooCommerce + WooCommerce extensions in larger project and not waste too much to much time on the particulars of WooGraphQL like session management or checkout, the create-woonext-app CLI generates a pre-created e-commerce application on Next.js application tailored to the developer/team.

npx create-woonext-app <license> [options]

The generated application utilizes the @woographql packages exclusive to the unlimited/annual subscribers of WooGraphQL Pro. So Go Subscribe! 😄. Below are more resources on the create-woonext-app CLI and @woographql packages.

  • create-woonext-app Homepage
  • create-woonext-app on NPM: The create-woonext-app README with more CLI usage instructions.
  • create-woonext-app Live Demo: fully decked out putting all current possible functionalities of the create-woonext-app on full display.
  • @woographql/next README: A Template generator CLI. Capable of generator a multitude of Next.js pages, Next.js Route Handlers, react components, react hooks, and utilities. It's also equipped to generate react component and hook stubs for speedy component create with no boilerplate.
  • @woographql/react-hooks README: React hook library acting as the backbone for UI connected to session, cart, and customer.
  • @woographql/session-utils README: Provides utilities for managing the WPGraphQL + WooGraphQL session tokens like a TokenManager, also provides interfaces and types for easy customization of said TokenManager or the complete creation of a custom TokenManager with minimal effort. The bundled TokenManager implemented utilizes browser storage (Local/Session storage), so if you'd prefer something like Iron Session this might be the route for you.
  • @woographql/codegen README: A convenient wrapper for GraphQL Codegen providing a few configurations out of the box, with the ability to override the default configuration by creating a codegen.ts in the project root.

Wanna help support WooGraphQL's future

Follow alt textalt text

Demo/Examples

Who using WooGraphQL

Rocky Mountain Sewing & Vacuum Russemerket wohnparc.de
Rocky Mountain Sewing & Vacuum Russemerket wohnparc.de

Contributors

Code Contributors

This project exists thanks to all the people who contribute. [Contribute].

Financial Contributors

Become a financial contributor and help us sustain our community. [Contribute]

Individuals

Organizations

Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]

wp-graphql-woocommerce's People

Contributors

adrienpicard avatar ardiewen avatar believelody avatar creative-andrew avatar davevanhoorn avatar fabiojundev avatar hilmerx avatar hwsiew avatar jacobarriola avatar jasonbahl avatar jmotes avatar justlevine avatar khlieng avatar kidunot89 avatar kpoelhekke avatar krystianjj avatar lstellway avatar manuelsampl avatar matthijs166 avatar monkeywithacupcake avatar namli avatar oskarmodig avatar ramyareye avatar ranaaterning avatar renatonascalves avatar saleebm avatar sbolinger-godaddy avatar scottyzen avatar stevezehngut avatar victormattosvm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wp-graphql-woocommerce's Issues

Add a centralize product attribute connection

Is your feature request related to a problem? Please describe.
As v0.1.0 individual product attributes must be known at the root level to be accessed. For example say to have an attribute color, The client must already know that paColor exists in order to query the corresponding data from the root.

Describe the solution you'd like

  • ProductAttribute type
  • productAttribute query
  • productAttributes connection

Query products by categories returns an empty array.

When I run the following query to get products by categories, it return an empty array, though there are products assigned to categories.

QUERY

  productCategories {
    pageInfo {
      hasNextPage
      endCursor
    }
    nodes {
      id
      name
      slug     
      productCategoryId
      products {
        edges {
          node {
            id
          }
        }
      }
    }
  }
}

**RESULT**

{
 “data”: {
   “productCategories”: {
     “pageInfo”: {
       “hasNextPage”: false,
       “endCursor”: “YXJyYXljb25uZWN0aW9uOjY2"
     },
     “nodes”: [
       {
         “id”: “cHJvZHVjdF9jYXQ6NjEx”,
         “name”: “Clothing”,
         “slug”: “clothing”,
         “productCategoryId”: 611,
         “products”: {
           “nodes”: []
         }
       }
     ]
   }
 }
}

Add name to ProductVariation

Really need name in ProductVariation type as this is useful for displaying specific names for specific variations example: "Hard Cover", "Soft Cover", "eBook"

Schema validation fails for product types

Describe the bug
Since updating to v0.3.0, Apollo client does not download the schema from my remote server anymore because it cannot validate the schema. To sum up the error message, it says that the different Product Types, ie VariableProduct do not match to the interfaces expected from the Product type (ie expected ProductToProductCategoryConnection for Product.Category but getting VariableProductToProductCategoryConnection).

To Reproduce
Steps to reproduce the behavior:

  1. I thought it was related to my install, but then I grabbed the Docker image here and set it up.
  2. Then I ran:
    $ apollo client:download-schema --endpoint http://localhost:8091/graphql
  3. And then I got the following error:
✖ Saving schema to schema.json
→ Interface field argument Product.upsell(where:) expects type ProductToProductConnectionWhereArgs but SimpleProduct.upsell(where:) is type SimpleProductToProductConnectionWhereArgs.

Error: Interface field Product.categories expects type ProductToProductCategoryConnection but VariableProduct.categories is type VariableProductToProductCategoryConnection.

Interface field argument Product.categories(where:) expects type ProductToProductCategoryConnectionWhereArgs but VariableProduct.categories(where:) is type VariableProductToProductCategoryConnectionWhereArgs
...
Interface field Product.upsell expects type ProductToProductConnection but SimpleProduct.upsell is type SimpleProductToProductConnection.
Interface field argument Product.upsell(where:) expects type ProductToProductConnectionWhereArgs but SimpleProduct.upsell(where:) is type SimpleProductToProductConnectionWhereArgs.
    at assertValidSchema (~/.config/yarn/global/node_modules/graphql/type/validate.js:71:11)
    at assertValidExecutionArguments (~/.config/yarn/global/node_modules/graphql/execution/execute.js:136:35)
    at executeImpl (~/.config/yarn/global/node_modules/graphql/execution/execute.js:86:3)
    at execute (~/.config/yarn/global/node_modules/graphql/execution/execute.js:64:63)
    at Object.introspectionFromSchema (~/.config/yarn/global/node_modules/graphql/utilities/introspectionFromSchema.js:31:37)
    at Task.task (~/.config/yarn/global/node_modules/apollo/lib/commands/client/download-schema.js:15:78)

Expected behavior
I would expect to get a schema from my client installation. However, I just download the schema manually and it is fine for me since the queries resolve for all the product types well.

Screenshots
...

Desktop (please complete the following information):
...

Smartphone (please complete the following information):
...

Additional context
It seems that it's difficult for one to simply validate a schema by any other means than to just run apollo client:download-schema, I can't find any tools to help with this besides a schema linter.
I don't if this makes sense, but also it seems that the interface for the extended Product Types just needs to implement the default Product one. I hope to help as much as I am able to. Thank you guys for all your effort and hard work.

Customer mutations

Documenting coming Customer mutations. More are likely to be added, concerning payment and shipping method

Customer Mutations to implemented

  • registerCustomer
  • updateCustomerAddress

TaxClass type

Design Notes

  • WPEnum type
  • Wraps tax class objects.
  • Used frequently throughout schema.
  • Values stored by the enumeration should be a tax class slug. Eg. zero-rate, standard, reduced-rate
  • Slugs for values stored by the enumeration should be the tax name formatted with WPEnum::get_safe_name. Eg. ZERO_RATE, STANDARD_RATE, REDUCED_RATE.

Pagination broken

This has be confirmed for products connection using the query below. It's safe to assume the problem persisted across all ConnectionResolvers extending AbstractConnectionResolver, since pagination is defined virtually the same for each of them.

query GET_PRODUCTS($first: Int $after: String) {
    products(first: $first after: $after) {
      pageInfo {
        hasNextPage
        endCursor
      }
      nodes {
        productId
        name
        description
        slug
        image {
          altText
          uri
          sourceUrl
        }
      }
    }
  }

Product mutations

Description

Mutations for manipulating Products and ProductVariations. Capability checks will be implemented so this mutations won't be usable for user without them.

Mutations

  • createProduct - creates a product
  • createVariation - creates a product variation
  • updateProduct - modifies an existing product
  • updateVariation - modiifies an existing product variation
  • deleteProduct - deletes a product
  • deleteVariation - deletes a product variation

Order Creation directly

There is a mutation missing via which I was able to make an order without even putting it on the cart and cannot find it on the mutation and anywhere.

productBy query should support querying by slug

Is your feature request related to a problem? Please describe.
When routing, a common use case is to need to find a post object by its slug. Other WPGraphQL queries like postBy and pageBy have a uri input field for this, but productBy does not.

Describe the solution you'd like
Add a uri input field to productBy.

Describe alternatives you've considered
You can use the products query and take just the first result, but it's a kludge.

Release v0.0.4 Summary

Release Notes

  • Querying products and variations by product attribute implemented. #50
  • More fields added to the ProductVariation type schema. A new WPObject type VariationAttribute implemented. #49
  • restricted_cap filter added. #53
  • Fixed bug related to ProductCategoryToProduct and ProductTagToProduct connections #44

Add AND and OR statement to where clause.

Is your feature request related to a problem? Please describe.
When creating a product filter for example, you will often want to filter the same field more than once. Then it would be great to have the AND added to the where clause. The same goes for the OR.

Describe the solution you'd like
This type of solution would be great:
where: {OR: [ {categoryName: "All"}, {categoryName: "pants" } ] }

Describe alternatives you've considered
Perhaps enabling support for the product type when using the tax Query plugin.

Order-Item type queries

Description

A WPObject that encompasses the WC_Order_Item, WC_Order_Item_Coupon, WC_Order_Item_Fee, WC_Order_Item_Product, WC_Order_Item_Shipping, and WC_Order_Item_Tax crud classes.

Connection

  • items - From the Order and Refund types.
query {
      order( id: $order_id ) {
            couponLines {
                ...
            }
            feeLines {
                ...
            }
            lineItems {
                ...
            }
            shippingLines {
                ...
            }
            taxLines {
                ...
            }
      }
}

Order mutations

Description

Mutations for manipulating Orders. Capability checks will be implemented so this mutations won't be usable for user without them.

Mutations

  • createOrder - creates a order
  • updateOrder - modifies an existing order
  • deleteOrder - deletes a order
  • checkout - creates order from cart

Refund mutations

Description

Mutations for manipulating Refunds. Capability checks will be implemented so this mutations won't be usable for user without them.

Mutations

  • createRefund - creates a refund
  • updateRefund - modifies an existing refund
  • deleteRefund - deletes a refund

Custom attributes of variable products cannot be queried.

Describe the bug
Retrieving the attributes field of variable products that contain custom attributes returns NULL with the following error for any custom attributes:

{
	"errors": [{
		"debugMessage": "Cannot return null for non-nullable field ProductAttribute.attributeId.",
		"message": "Internal server error",
		"category": "internal",
		"locations": [{
			"line": 39,
			"column": 11
		}],
		"path": ["products", "nodes", 0, "attributes", "nodes", 2, "attributeId"]
	}]
}

To Reproduce
Steps to reproduce the behavior:

  1. Create a product with custom attributes.
  2. Attempt to query the attributes:
{
  productBy(id: "x") {
    attributes {
      nodes {
        attributeId
      }
    }
  }
}

Expected behavior
No error or warning.

Release v0.1.0 Summary

Description

Some mutations, a type, and a slight folder structure change.

Mutations

  • Customer
    • registerCustomer #55
    • updateCustomer #67
  • Cart

Types

Changes

  • src directory renamed to includes #73

Cart mutations

Description

Mutations for manipulating the Cart.

Mutations

  • addItem - adds an item to the cart
  • updateItem - modifies an item in the cart
  • removeItem - removes an item from the cart
  • removeItems - removes multiple or all items from the cart
  • addCoupon - adds a coupon to the cart
  • updateCoupon - modifies a coupon on the cart
  • removeCoupon - removes a coupon from the cart
  • removeCoupons - removes multiple or all coupon from the cart
  • clearCart - removes all coupons and items from the cart.

Help using the `checkout` mutation to create orders.

Describe the bug
I am using graphql for create orders from the postman. queries are working fine but I can't run any mutations there is always customer capability error. I am also sending the Bearer token in header to authenticate the customer

To Reproduce
Steps to reproduce the behavior:

  1. http://localhost:8888/testsite/graphql or https://woographql.axistaylor.com/graphql
  2. Headers
    Content-Type:application/graphql Authorization:Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczpcL1wvd29vZ3JhcGhxbC5heGlzdGF5bG9yLmNvbSIsImlhdCI6MTU3MDAyMTg1OCwibmJmIjoxNTcwMDIxODU4LCJleHAiOjE1NzAwMjIxNTgsImRhdGEiOnsidXNlciI6eyJpZCI6IjMifX19.7drzb9beicfl-SqbPZvzseBGoY4Cf30eoS0x1wyGQIE
  3. run this mutation
mutation MyMutation {
createOrder(input: {clientMutationId: "CreateOrder", customerId: 6, paymentMethod: "bacs", paymentMethodTitle: "Direct Bank Transfer", billing: {address1: "969 Market", city: "San Francisco", address2: "", company: "", country: US, email: "[email protected]", firstName: "John", lastName: "Doe", phone: "12903402832", postcode: "94103", state: "CA"}, shippingLines: {methodId: "flat_rate", methodTitle: "flat_rate", total: "10"}, shipping: {address1: "969 Market", address2: "", city: "San Francisco", country: US, email: "[email protected]", firstName: "JOhn", lastName: "Doe", phone: "180923843204", postcode: "94103", state: "CA"}, isPaid: true, lineItems: {productId: 30, quantity: 1}}) {
  clientMutationId
  order {
    cartHash
    currency
  }
}
}

Expected behavior
The order should be created

Screenshots
Request Screenshot

image

Screenshot 2
Screenshot 2019-10-02 at 5 48 38 PM
Screenshot 3
image

Cart type and queries

Description

A wrapper WPObject type Cart for the class WC_Cart.

Queries

  • cart - for accessing WooCommerce instance in a manner similar to the viewer query.
query {
    cart{
        total
        subtotal
        items {
             nodes {
                 ...
             }
        }
    }
}

Add filter for restricted_cap in models

Adds a wordpress filter to restricted_cap property in Model class

Potential Solution
Something like this for the models that extend Crud_CPT.

$restricted_cap = apply_filters(
  $this->post_type_object->name,
  $this->get_restricted_cap()
);

And something like this for other models that only extend Model

$restricted_cap = apply_filters(
  'Model_Name',
  $this->get_restricted_cap()
);

Order id undefined

I am trying to debug why the checkout mutation succeeds without actually creating an order in wordpress. I enabled the logs and wordpress complains about $order_id on the very last function in includes/data/mutation/class-checkout-mutation.php. I guess if the condition fails the order_id is undeclared.

ShippingZone and ShippingMethodInstance type

Shipping Zone - Design Notes

  • WPObject type
  • Queries shipping zone object
  • Has root query and root connections
  • Queryable from ShippingMethodInstance type

ShippingMethodInstance - Design Notes

  • WPUnion or WPInterface type
  • Queries shipping method instances
  • No root query or connections
  • Queryable from ShippingLine type

Notes

  • Only queries needed for customer-level functionality

Hooks for mutations

I'd like to suggest something, but I wanna see what you think first @kidunot89

I was taking a closer look at the current mutations and the way they are organized is pretty good. I'd like to propose more hooks so that third party plugins can have more flexibility.

Input fields

Those fields could be filterable so that one could add or remove them. Think of a WooCommerce Subscriptions integration, either they would have to create their own mutation or they could integrate in the current mutation.

Mutate and get payload

The current hooks in place are very good. I think we could expand that to all mutations though, so that all of them have support.

Output fields

The response of the mutation also needs a hook. So that plugin authors can add more data if necessary or remove duplicated ones.

Permission Checks

This is a personal opinion but I think all mutation requires a permission check. Even if the mutation is public.

Plugin authors and site owners need the power to disable or give access based on roles or any other criteria.

Overall, right now if I'm a plugin author wishing to create an integration to the current plugin, is not easy. Let's facilitate that adding some hooks.

I understand that this can be misused. But I'd argue this is a good tradeoff.

I'm happy to put a PR together. But I'd like your opinion on that first. :)

Union Filter Callback missing

Describe the bug
This issue (wp-graphql/wp-graphql-acf#84) was opened about unions having issues, and in testing locally it seems to be an issue with a missing callback in this plugin.

The callback for graphql_union_resolve_type appears to not exist here in this class:

add_filter( 'graphql_union_resolve_type', array( __CLASS__, 'graphql_union_resolve_type' ), 10, 3 );

This causes unions to not resolve properly.

To Reproduce
Steps to reproduce the behavior:

  1. Execute a query that includes asking for fields of a union

Expected behavior
The fields of the union should resolve, or at least not return an error

Screenshots
With WPGraphQL for WooCommerce Active:
Screen Shot 2019-10-30 at 2 51 09 PM

With it de-activated (working):
Screen Shot 2019-10-30 at 2 51 56 PM

Additional context

Tested with the following plugin versions

WPGraphQL v0.4.0
WPGraphQL for ACF v0.3.0
WPGraphQL for WooCommerce v0.3.0

categoryNameIn not filtering

Hello,

I was trying to filter product by category names but noticed that I always get all of the data. This filter doesn't work. If I change it to categoryIn it works as expected. I double checked this in Altair graphql plugin and I saw the same bug.

categoryNameIn [String]
Limit result set to products assigned to a group of specific categories by name.

The ProductAttribute type is incomplete

Describe the bug
ProductAttribute is an incomplete type. I've simple just wrapped the object return by WC_Product::get_attributes() and WC_Product::get_default_attributes(). I'll have to do more research the issue.

To Reproduce

{
    product(id: "some-id"){
       attributes {
           ...
       }
       defaultAttributes {
           ...       
       }
   }
}

Expected behavior
That's the issue. I don't know yet. I would love some input on how everyone thinks this should be shaped.

customerRegister mutation resolves wrong object for `viewer` field

Describe the bug
The resolver for the viewer field of the customerRegister mutation returns a WPGraphQL\Model\User, but the JWT plugin expects a \WP_User object.

Attempting to use any JWT fields in the resulting viewer field gives the following error:

Argument 1 passed to WPGraphQL\JWT_Authentication\ManageTokens::WPGraphQL\JWT_Authentication\{closure}() must be an instance of WP_User, instance of WPGraphQL\Model\User given

To Reproduce
Install wp-graphql-jwt-authentication, and perform the following mutatoin:

mutation RegisterMutation($input: RegisterCustomerInput!) {
  registerCustomer(input: $input) {
    viewer {
      jwtAuthToken
      jwtRefreshToken
    }
  }
}

Other mutations

Mutations that don't have a direct connection to a type.

  • requestARefund - mutation for a customer to request a fund

Product variation attributes

I am seeing two bugs with product attribute variations. The name field returns the wordpress field name. Maybe add Label Field as well? Also for sizes the value is empty.

With the current design I don't know if it's possible to build the default product page. See screenshot.

image

image

Pagination with orderby when fetching Products causes products to be skipped

I've been working with paginating through products combined with custom filters and sorting which has led to some strange behaviour where products are skipped over and cursors ignored.

Paginating through a list of products returned from products for a category seems to work fine, but when I add an order I see the following.

If I start with a category that has 8 products in it and I fetch all 8 at once, they are ordered correctly as expected:

Query

query getProduct {
  products(where: {orderby: {field: PRICE, order: DESC}, categoryId: 24}, first: 8, after: "") {
    pageInfo {
      startCursor
      endCursor
    }
    nodes {
      name
      id
      price
    }
  }
}

Returns

{
  "data": {
    "products": {
      "pageInfo": {
        "startCursor": "YXJyYXljb25uZWN0aW9uOjIwMDY=",
        "endCursor": "YXJyYXljb25uZWN0aW9uOjEyMzM="
      },
      "nodes": [
        {
          "name": "Product A",
          "id": "cHJvZHVjdDoyMDA2",
          "price": "£13.95"
        },
        {
          "name": "Product B",
          "id": "cHJvZHVjdDoxMjM2",
          "price": "£12.95"
        },
        {
          "name": "Product C",
          "id": "cHJvZHVjdDoxMjI2",
          "price": "£12.95"
        },
        {
          "name": "Product D",
          "id": "cHJvZHVjdDoxNDAy",
          "price": "£10.95"
        },
        {
          "name": "Product E",
          "id": "cHJvZHVjdDoxMjMy",
          "price": "£7.95"
        },
        {
          "name": "Product F",
          "id": "cHJvZHVjdDoxOTgy",
          "price": "£4.95"
        },
        {
          "name": "Product G",
          "id": "cHJvZHVjdDoxOTcy",
          "price": "£4.95"
        },
        {
          "name": "Product H",
          "id": "cHJvZHVjdDoxMjMz",
          "price": "£3.95"
        }
      ]
    }
  }
}

All good so far...

Now if I limit the page size to 2, I get the first two results as expected...

Query:

query getProduct {
  products(where: {orderby: {field: PRICE, order: DESC}, categoryId: 24}, first: 2, after: "") {
    pageInfo {
      startCursor
      endCursor
    }
    nodes {
      name
      id
      price
    }
  }
}

Returns

{
  "data": {
    "products": {
      "pageInfo": {
        "startCursor": "YXJyYXljb25uZWN0aW9uOjIwMDY=",
        "endCursor": "YXJyYXljb25uZWN0aW9uOjEyMzY="
      },
      "nodes": [
        {
          "name": "Product A",
          "id": "cHJvZHVjdDoyMDA2",
          "price": "£13.95"
        },
        {
          "name": "Product B",
          "id": "cHJvZHVjdDoxMjM2",
          "price": "£12.95"
        }
      ]
    }
  }
}

Again, this seems fine. However if I now use the end cursor value to fetch the next page, I see the following.

Query

query getProduct {
  products(where: {orderby: {field: PRICE, order: DESC}, categoryId: 24}, first: 2, after: "YXJyYXljb25uZWN0aW9uOjEyMzY=") {
    pageInfo {
      startCursor
      endCursor
    }
    nodes {
      name
      id
      price
    }
  }
}

Returns

{
  "data": {
    "products": {
      "pageInfo": {
        "startCursor": "YXJyYXljb25uZWN0aW9uOjEyMzI=",
        "endCursor": "YXJyYXljb25uZWN0aW9uOjEyMzM="
      },
      "nodes": [
        {
          "name": "Product E",
          "id": "cHJvZHVjdDoxMjMy",
          "price": "£7.95"
        },
        {
          "name": "Product H",
          "id": "cHJvZHVjdDoxMjMz",
          "price": "£3.95"
        }
      ]
    }
  }
}

For some reason, using the cursors and paginating while having ordered by price causes Products C, D, F and G to be skipped. If I look at their cursors using the edges value and then fetch by their individual cursors, I can still retrieve them.

Also I have no other plugins installed beyond the basic WPGraphQl setup so there shouldn't be anything conflicting.

I'm new to Wordpress so if there is anything else that would be useful for me to add to the issue to help debug this, let me know!

Ajax call /?wc-ajax=get_refreshed_fragments clears cart when plugin installed

Steps to reproduce the behavior:
I have installed vanilla Woocommerce with Storefront theme and this plugin with wp-graphql.

When I click add to cart the product is added to the cart and page refreshed with correct items in cart. However on page load there is an ajax call /?wc-ajax=get_refreshed_fragments. Response from that cart clears cart_hash cookie and returns 0 products in cart.

This does not happen when plugin is deactivated.

Screenshots
Screenshot 2019-09-25 at 08 12 35

subcategory shows empty when image field is present

Describe the bug
When the subcategory and image fields are together then the subcategory field always shows empty when the product does have a subcategory.

To Reproduce
Steps to reproduce the behavior:

  1. Make a query for a product that you know has a subcategory
  2. Add the image field and the subcategory field in the query.
  3. The query will display empty in the subcategories
  4. Remove image and the subcategories will show up.

Expected behaviour
The expected behaviour is that the subcategories should show up even if the image field is present.

Screenshots
Screenshot 2019-09-13 at 11 17 50
1. query for a product with both image and subcategory field

Screenshot 2019-09-13 at 11 18 41
2. query for a product with only the subcategory field

Desktop (please complete the following information):

  • OS: [iOS]
  • Browser [chrome]
  • Version 75.0.3770.142 (Official Build) (64-bit)

Sorting of products, Categories etc

Is your feature request related to a problem? Please describe.
Product Sorting features is what really missing with in your Project, Project Sorting can be of different type. Right now filtering is available but sorting is much more need.
Types of Sorting that are required.

Describe the solution you'd like
I have attached link and the code will pretty much gonna help you with the function itself all you have to do it make it accessible with Graphql.

Provide guest user authentication

Describe the bug
Cart items for guest users have no way of being persisted. This is due to the fact that there is current no way to identifying individual guest users client-side.

To Reproduce
Steps to reproduce the behavior:

  1. Add an item to the cart using a cart mutation
  2. Refresh the browser page
  3. Query the cart

Expected behavior
Cart items should be persisted between request.

Product post_type should be set to `show_in_graphql`

Describe the bug
Currently, the Product Type is registered to the Schema without respect to post_type registry.

Since Products in WooCommerce are Post Types, we should use the Post Type registry to set the post_type to show_in_graphql instead of registering the Product type without connection to the Post Type it represents.

By extending the Post Type registry, other plugins can know what Post Types are exposed to GraphQL.

For example, the WPGraphQL for ACF plugin checks for all post types that are set to show_in_graphql using the following:

get_post_types( 'show_in_graphql' => true ) and the product post type isn't included because the Post Type registry has no knowledge that the Product post_type is exposed to GraphQL.

We should make use of the internal WordPress registries as much as possible and extend them so that other tools in the ecosystem can benefit as much as possible.

Customer id doesn't match user id

I am using this plugin and the recommended woocommerce plugin. The problem is that ids don't match so when a user logs in I save their id and when they are ready to checkout I query for customer(id: ID) but the problem is that these id's don't match. If you provide the default db id's graphql complains. Shouldn't they share the same ids?

Here is the result of the queries.

"data": {
    "customers": {
      "nodes": [
        {
          "email": "[email protected]",
          "username": "test",
          "id": "Y3VzdG9tZXI6Mg==",
          "customerId": 2
        },
"users": {
     "nodes": [
       {
         "email": "[email protected]",
         "username": "test",
         "id": "dXNlcjoy",
         "userId": 2
       },

Price Type, and name not showing up for product as Typed values

Describe the bug
Just installed plugin along side WP Graphql and tried to do the basic query on products following the example in the docs. Unfortunately it does return the data correctly, but price, type and , name don't seem to be "typed" and are showing red underlines with the following error: Cannot query field name on type Product.

To Reproduce
Steps to reproduce the behavior:

  1. Go to 'https://shopapi.every-tuesday.com/graphql'
  2. Query an example

Expected behavior
A clear and concise description of what you expected to happen.
Expect to be able to be typed correctly.

** Env
Wordpress environment on wpengine. Using GraphQL playground for mac descktop v.1.8.1
WC - version 3.7
WP - version 5.2.2

Support update of multiple quantities in cart in a single mutation

Is your feature request related to a problem? Please describe.
Currently, only a single CartItem can be updated at a time when calling updateItemQuantity. Given that it's a common operation to have a list of quantities and an "update cart" button on a shopping cart page, this is awkward.

Describe the solution you'd like
updateItemQuantity, or a new mutation like updateItemQuantities, should accept an array of CartItem keys and quantities, to allow for updating the cart quantities in a single mutation.

Describe alternatives you've considered
Multiple top level mutations, but this is really awkward in Apollo -- for example, using the <Mutation> component is a non-starter, and additional code is needed to generate multiple named mutations and then parse the results.

Accessing meta_data product property?

Do we have meta_data product property, much like WC REST API?

I have tried the following which works just fine, but I'm missing the meta_data product property...

{
  products {
    edges {
      node {
        sku
        name
        status
        manageStock
        regularPrice
        salePrice
        dateOnSaleFrom
        dateOnSaleTo
        stockQuantity
        taxClass
      }
    }
  }
}

Tests needed

Connection Tests

  • Term to Product
  • Product to MediaItem

Modelless WPObjectType Test

  • CustomerAddress
  • ProductAttribute
  • ProductDownload
  • ProductRatingCount - type being removed.

Add format argument to product pricing fields

Is your feature request related to a problem? Please describe.

  • As of v0.1.0 the pricing fields in Product and ProductVariation types return un-formatted string values, which is counter-productive.

Describe the solution you'd like

  • The fields should return a formatted string by default, eg "$19.99", "$19.99 - $29.99", ...etc, and when the format: RAW is passed as an argument, a raw float value should be returned, eg 19.99, 29.99...etc.
  • The dual typing will be implemented using a simple union type. PricingUnion
  • resolver for the corresponding format: RAW input will require product CPT edit_post cap to resolve.

Coupon Mutations

Description

Mutations for manipulating Coupons. Capability checks will be implemented so this mutations won't be usable for user without them.

Mutations

  • createCoupon - creates a coupon
  • updateCoupon - modifies an existing coupon
  • deleteCoupon - deletes a coupon

Extension breaks the hierarchy between pages

Once the extension is enabled, the hierarchy between pages is incorrect.

To Reproduce
Using the query below in the Playground or in your own environment.

query GET_PAGES {
  pages {
    edges {
      node {
        id
        slug
        childPages {
          nodes {
            id
            slug
          }
        }
      }
    }
  }
}

Result when the extension is enabled

{
  "data": {
    "pages": {
      "edges": [
        {
          "node": {
            "id": "cGFnZTo1MQ==",
            "slug": "menu",
            "childPages": {
              "nodes": [
                {
                  "id": "cGFnZTo1MQ==",
                  "slug": "menu"
                },
                {
                  "id": "cGFnZTo0OQ==",
                  "slug": "my-title"
                }
              ]
            }
          }
        },
        {
          "node": {
            "id": "cGFnZTo0OQ==",
            "slug": "my-title",
            "childPages": {
              "nodes": [
                {
                  "id": "cGFnZTo1MQ==",
                  "slug": "menu"
                },
                {
                  "id": "cGFnZTo0OQ==",
                  "slug": "my-title"
                }
              ]
            }
          }
        }
      ]
    }

Expected result (extension disabled)

{
  "data": {
    "pages": {
      "edges": [
        {
          "node": {
            "id": "cGFnZTo1MQ==",
            "slug": "menu",
            "childPages": {
              "nodes": []
            }
          }
        },
        {
          "node": {
            "id": "cGFnZTo0OQ==",
            "slug": "my-title",
            "childPages": {
              "nodes": []
            }
          }
        }
      ]
    }
  }
}

Plugin hooks with same key as WooCommerce core

I have a question about how we are naming hooks in the plugin. I can see several hooks being used, some with the same key as the WooCommece core and I'm not sure if it was deliberate or not.

This hook has the same key as Woo core one. Should that not be prefixed?!

return apply_filters( 'woocommerce_new_cart_item_data', $cart_item_args, $input, $context, $info );

Also, maybe we could prefix all hooks from this plugin with woocommerce_graphql or graphql_woocommerce.

What do you think?!

no queries work

I tried out the master branch with wpgraphql 0.3.2 and querying for product didn't work. I tried the develop branch and it gave my site a 500 error. It's a broad question but are there any tips for getting it to work?

Here is a test query:

query GET_PRODUCTS {
  products {
    edges {
      node {
        id
      }
    }
  }
}

Unsetting "object_ids" on all connections

Describe the bug
The filter added to graphql_term_object_connection_query_args is unsetting $query['object_ids'] without checking the type that is being worked with. This means that if you want to limit connection terms to their object, you can't even if you set shouldOnlyIncludeConnectedItems.

To Reproduce
This query should only return 1 category on my side but it returns them all.

query getPosts {
    posts {
      edges {
        node {
          postId
          title
        	categories(where: {
            shouldOnlyIncludeConnectedItems: true
          }) {
            edges {
              node {
                name
              }
            }
          }
        }
      }
    }
  }

Expected behavior
The WooCommerce term connection should only unset "object_ids" on WooCommerce types and not effect other connections.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.