GraphQL: Cannot query field "id" on type "searchProducttypeOutput"

Help for integrating the Laravel package
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
kdim95
Advanced
Posts: 208
Joined: 26 Aug 2022, 12:17

GraphQL: Cannot query field "id" on type "searchProducttypeOutput"

Post by kdim95 » 26 Apr 2024, 04:26

Laravel framework version: 11.3.1
Aimeos Laravel version: 2024.04
PHP Version: 8.2.17
Environment: Linux

Hello,

I'm getting this error:
Cannot query field "id" on type "searchProducttypeOutput"

Code snippet, used in custom.js in my extension:

Code: Select all

let filter = {
	"==": {"product.type.domain":"product"}
};
const fstr = JSON.stringify(JSON.stringify(filter));
const body = JSON.stringify({'query':
`query {
	searchProductTypes(filter: ` + fstr + `) {
	id
	code
	label
	}
}`});

fetch($('.aimeos').data('graphql'), {
	method: 'POST',
	credentials: 'same-origin',
	headers: { // Laravel only
		'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
	},
	body: body
}).then(response => {
	return response.json();
}).then(data => {
	console.log(data);
});
I'm using the example from here:
https://aimeos.org/docs/2024.x/admin/graphql/type/

Best regards

User avatar
aimeos
Administrator
Posts: 7917
Joined: 01 Jan 1970, 00:00

Re: GraphQL: Cannot query field "id" on type "searchProducttypeOutput"

Post by aimeos » 26 Apr 2024, 11:20

Sorry, the documentation wasn't up to date and the correct query in 2024.x+ is:

Code: Select all

query {
  searchProductTypes(filter: "{\"==\": {\"product.type.domain\":\"product\"}}") {
    items {
      id
      code
      label
    }
    total
  }
}
The "total" property is optional and you should only add it if you need the total number of items matching the query for pagination.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

kdim95
Advanced
Posts: 208
Joined: 26 Aug 2022, 12:17

Re: GraphQL: Cannot query field "id" on type "searchProducttypeOutput"

Post by kdim95 » 26 Apr 2024, 11:53

Thank you, I got it working.

For some reason, when adding the filter parameter and using the query with Aimeos.query(), it requires the content of "filter" to be escaped with double slash, not single, don't know why that is, but it works now.

Code: Select all

const result = await Aimeos.query(`query {
	searchProductTypes( filter: "{ \\"==\\": { \\"product.type.domain\\": \\"product\\" } }" ) {
		items {
			id
			code
			label
		}
		total
	}
}`);
Best regards

User avatar
aimeos
Administrator
Posts: 7917
Joined: 01 Jan 1970, 00:00

Re: GraphQL: Cannot query field "id" on type "searchProducttypeOutput"

Post by aimeos » 26 Apr 2024, 12:12

Thanks for the hint, the docs has been adapted accordingly!
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply