Magento 2: GraphQl

Posted Almost 2 years ago. Visible to the public.

How to create a query with single input and output

Following graphql is defined schema.graphqls with Integer input and String output

type Query {
      testing(id: Int!): String @resolver(class: "Vasan\\TesterGraphQl\\Model\\Resolver\\Testing")
}

The Testing Resolver Class

class Testing implements ResolverInterface {


    /**
     * @param Field $field
     * @param \Magento\Framework\GraphQl\Query\Resolver\ContextInterface $context
     * @param ResolveInfo $info
     * @param array|null $value
     * @param array|null $args
     * @throws \Magento\Framework\Exception\LocalizedException
     */
    public function resolve (Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) {

        return 'testing';
    }
}

Testing in Altair as follows

query {
  testing(id: 17) 
}

vasan
Last edit
Almost 2 years ago
vasan
Keywords
Single, Input, and, output, graphQl
Posted by vasan to vasan's deck (2022-05-11 05:38)