Git Product home page Git Product logo

Comments (11)

dborsatto avatar dborsatto commented on May 28, 2024

Hey @dstuessy 🙂
Can you provide some more info, so we can try to understand your problem? I'm interested in what the expected result is compared to the actual result, and the different behavior you experience when using setInclude.

Contentful's API uses include=1 when no explicit parameter is defined, and the SDK should resolve links automatically, at the cost of an extra query, so using setInclude or not should yield the same result, with the underlying difference of having done more queries behind the scenes. Let me know your answers to my question above, so we can start debugging your issue 👍

from contentful.php.

dstuessy avatar dstuessy commented on May 28, 2024

Hi @dborsatto

Hm... maybe it's just a matter of me misreading the docs. haha

Here is what I expected to get:

{
    "sys": {
        "type": "Array"
    },
    "total": 1,
    "skip": 0,
    "limit": 100,
    "items": [
        {
            "sys": {},
            "fields": {
                "title": "Cars",
                "content": [
                    {
                        "sys": {
                            "type": "Link",
                            "linkType": "Entry",
                            "id": "_id"
                        }
                    },
                    {
                        "sys": {
                            "type": "Link",
                            "linkType": "Entry",
                            "id": "_id"
                        }
                    }
                ]
            }
        }
    ],
    "includes": {
        "Entry": [ {}, {} ]
    }
}

but actually got this:

{
    "sys": {
        "type": "Array"
    },
    "total": 1,
    "skip": 0,
    "limit": 100,
    "items": [
        {
            "sys": {},
            "fields": {
                "title": "Cars",
                "content": [
                    {
                        "sys": {
                            "type": "Link",
                            "linkType": "Entry",
                            "id": "_id"
                        }
                    },
                    {
                        "sys": {
                            "type": "Link",
                            "linkType": "Entry",
                            "id": "_id"
                        }
                    }
                ]
            }
        }
    ]
}

Using https://cdn.contentful.com/spaces/{my_space}/entries?access_token={my_token}&content_type={type}&fields.title=Cars&include=2 with a cURL request, seems to give me the former, though.

from contentful.php.

dborsatto avatar dborsatto commented on May 28, 2024

That looks weird indeed.
What do you say about opening a support ticket on contentul.com? So I can better take a look at your issue and see what we can find out 🙂 Please reference this Github issue 👍

from contentful.php.

dstuessy avatar dstuessy commented on May 28, 2024

Hi @dborsatto :)

Sorry for the extremely late reply. I'll open a support ticket with this github issue as a reference!

from contentful.php.

M-Porter avatar M-Porter commented on May 28, 2024

@dborsatto any update on this? As this is a public SDK it would be great to link the outcome of the support ticket as well as any corresponding commits and merges as the documentation is severely lacking. Thanks!

from contentful.php.

dborsatto avatar dborsatto commented on May 28, 2024

Hey @M-Porter,

Daniel created a support ticket, but then he never replied with some info I asked, so the ticket was archived.

For this case, are you having a similar issue? To be honest I can't fully understand the initial problem because the examples were about JSON, whereas the SDK should work as an abstraction thus making the underlying JSON irrelevant. Do you have any input on the topic?

Cheers,

Davide

from contentful.php.

dborsatto avatar dborsatto commented on May 28, 2024

Hey,

I'm closing this (again). If you have any more questions, don't hesitate to reach out.

Davide

from contentful.php.

balazsotakomaiya avatar balazsotakomaiya commented on May 28, 2024

The returned ResourceArray does not seem to include the "includes" array that both the API and the Javascript SDK return.

from contentful.php.

dborsatto avatar dborsatto commented on May 28, 2024

@officialbalazs The SDK handles the includes array internally and does not directly expose it. When you try to access those resources (through the original entry) the SDK will know that they've already been preloaded, and will not make further requests.

from contentful.php.

balazsotakomaiya avatar balazsotakomaiya commented on May 28, 2024

Aha - makes sense. Is there a way to expose that array?

It would save us from having to make subsequent requests to our API after fetching the original entry.

from contentful.php.

dborsatto avatar dborsatto commented on May 28, 2024

You can not access it, but as I said, there will be no extra API requests.

If the includes array contains an entry/asset, the SDK will not make extra requests when trying to fetch it (both when accessing it from another entry with something like $blogPost->getImage() or when calling $client->getAsset($assetThatWasAlreadyFetchedId)), because it will keep a copy of the resource in memory and use it instead of calling the API.

You can call $client->getMessages() for accessing a list of the API requests that have been made (it returns a list of Contentful\Core\Api\Message objects), and see for yourself that there shouldn't be extra API calls.

from contentful.php.

Related Issues (20)

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.