protected function parseServerRequest(
        ServerRequestInterface $serverRequest,
        FactoryInterface $factory,
        StoreInterface $store,
        CodecMatcherInterface $codecMatcher,
        $resourceType,
        $resourceId,
        $relationshipName,
        $relationships
    ) {
        /** If the resource id is not valid, throw a 404 exception. */
        if ($resourceId && !$this->doesResourceExist($store, $resourceType, $resourceId)) {
            throw new JsonApiException([], 404);
        }

        /** Do content negotiation. */
        $this->doContentNegotiation($factory, $serverRequest, $codecMatcher);

        /** Parse the server request into a JSON API inbound request object. */
        $inboundRequest = $factory->createInboundRequest(
            $serverRequest->getMethod(),
            $resourceType,
            $resourceId,
            $relationshipName,
            $relationships,
            $this->decodeDocument($serverRequest),
            $this->parseQueryParameters($serverRequest, $factory->createQueryParametersParser())
        );

        /** Check that there is a JSON API document if one is required for the type of request. */
        if ($this->isExpectingDocument($inboundRequest) && !$inboundRequest->getDocument()) {
            throw new DocumentRequiredException();
        }

        return $inboundRequest;
    }