- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Custom GraphQL queries not working Cannot query field "fiservGenerateTokenHash" on type "Query"
I have etc/schema.graphqls with the following example:
type Query{
fiservGenerateTokenHash: TokenHash @resolver(class: "Vendor\\Module\\GraphQL\\TokenHash")
}
I then have the TokenHash resolver
<?php namespace Vendor\Module\GraphQL; use Magento\Framework\GraphQl\Query\ResolverInterface; use Magento\Framework\GraphQl\Query\Resolver\ContextInterface; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; use Vendor\Module\Service\Encryption as EncryptionService; use Magento\Framework\GraphQl\Config\Element\Field; /** * Class TokenHash * @package Vendor\Module\GraphQL */ class TokenHash implements ResolverInterface { /** * @param EncryptionService $_encriptionService */ public function __construct( private readonly EncryptionService $_encriptionService ) { } /** * @param Field $field * @param ContextInterface $context * @param ResolveInfo $info * @param array|null $value * @param array|null $args * @return array */ public function resolve(Field $field, $context, ResolveInfo $info, array $value =null, array $args = null) { $tokenHash = $this->_encryptionService->generateNewHashBySessionId(); return ['token'=>$tokenHash]; } }
Now, when i run the basic test in postman to https://mydomain.com/graphql:
query { fiservGenerateTokenHash { token } }
All i get is this error: Cannot query field "fiservGenerateTokenHash" on type "Query"
This is driving me insane, i can't see anything wrong here
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: Custom GraphQL queries not working Cannot query field "fiservGenerateTokenHash" on typ
From what I see, your syntax looks correct.
You should verify that you’ve run the cache clearing commands, di-compiler, and set-up your modules.
Or you can get the Query by this command
curl -X POST \ https://your-magento-site.com/graphql \ -H "Content-Type: application/json" \ -d '{"query": "query { fiservGenerateTokenHash { token } }"}'
Mageplaza | Top-Rated Magento Extension and Solution Provider
Should you have any questions or concerns, feel free to contact us via consultant@mageplaza.com
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: Custom GraphQL queries not working Cannot query field "fiservGenerateTokenHash" on typ
It's looking like it's the GraphQL in general, i have the feeling one of the hundreds of modules we use is causing it. It won't be fun debugging this!