Giter Site home page Giter Site logo

Fields issue on preload entity about vulcain HOT 3 OPEN

dunglas avatar dunglas commented on April 29, 2024
Fields issue on preload entity

from vulcain.

Comments (3)

dunglas avatar dunglas commented on April 29, 2024

Could you paste the JSON documents you request, please?

from vulcain.

BenWaNH avatar BenWaNH commented on April 29, 2024

Hi @dunglas
Thanks for your time!
This is a screen of my output greetings
image
And the author
image

I tried more since my last post, it seems to work if Fields header match between author et greetings, what i mean, if for my get of authors/1 i've this:

.then(() => window.fetch('https://localhost/authors/1', {
        headers: {
            fields: '"/@id"'
        }
    })

I see this with query parameters example, so i thinks i should reporter "/hydra:member/*/author/@id" to /@id when i fetch him. Isn't it? So, why not, it works!

However, I don't know how to make work with a new level after (in my exemple, authors have comments)
So, i tried:

window.fetch('https://localhost/greetings?'/*+encodeURI('fields="/hydra:member/!*!/@id"&fields="/hydra:member/!*!/name"&fields="/hydra:member/!*!/author/firstName"')*/, {
        headers: {
            preload: '"/hydra:member/*/author/comments/*"',
            fields: '"/hydra:member/*/@id", "/hydra:member/*/name", "/hydra:member/*/author/@id", "/hydra:member/*/author/firstName", "/hydra:member/*/author/comments/*/@id"'
        }
    }).then(() => window.fetch('https://localhost/authors/1', {
        headers: {
            fields: '"/@id", "/firstName"'
        }
    }).then(() => window.fetch('https://localhost/comments/1', {
        headers: {
            fields: '"/@id"'
        }
    }))
    )

Good fields are displayed
image
image
but, no push...
image
I tried many case, but either i've good fields or push but never both :'(

I saw this syntax in your demo symfo repo:

const conferences = await fetchJson('/conferences', { headers: { Preload: "/hydra:member/*/@id/sessions/*/feedback/*" }});

I don't understand this syntax with the @id before sessions, but when i tried, all my next calls are push but without fields....

Do you have a full example somewhere with multi level and fields headers?

Thanks

from vulcain.

BenWaNH avatar BenWaNH commented on April 29, 2024

Hi @dunglas ,
sorry to come back, i know you're busy.

Just, do you know if is it possible to combine Fields and Preload to a nested level of relationship with current version of Vulcain?! Or i miss something that i misunderstand
Push is stopped after 1st level if i add fields (if i comment adding Fields all is pushed but without picked fields)
My last js script with query mode :

    let url = 'https://localhost/greetings?'
    // url += encodeURI('preload="/hydra:member/*/@id/author/comments/*"')
    // url += encodeURI('preload="/hydra:member/*/author/comments/*"')
    url += encodeURI('preload="/hydra:member/*/author"&preload="/hydra:member/*/author/comments/*"')
    url += encodeURI('&fields="/hydra:member/*/@id"&fields="/hydra:member/*/name"&fields="/hydra:member/*/author/@id"&fields="/hydra:member/*/author/firstName"&fields="/hydra:member/*/author/comments/*/@id"')
    // url += encodeURI('&fields="/hydra:member/*/@id"&fields="/hydra:member/*/name"&fields="/hydra:member/*/author/firstName"&fields="/hydra:member/*/author/comments/*/@id"')
    // url += encodeURI('fields="/hydra:member/*/@id"&fields="/hydra:member/*/name"')

    window.fetch(url).then(async (response) => {
        const json = await response.json()
        const greetings = json['hydra:member']
            window.fetch(greetings[0]['author'])
                .then(async(reponse2) => {
                    const author = await reponse2.json()
                    window.fetch(author.comments[0])
                })
    }
    )

My greetings collection:

{
    "hydra:member": [
        {
            "author": "/authors/1?fields=%22%2Fcomments%2F%2A%2F%40id%22%2C+%22%2F%40id%22%2C+%22%2FfirstName%22",
            "@id": "/greetings/1",
            "name": "TestABC"
        },
        {
            "author": "/authors/1?fields=%22%2Fcomments%2F%2A%2F%40id%22%2C+%22%2F%40id%22%2C+%22%2FfirstName%22",
            "@id": "/greetings/7",
            "name": "AAA"
        },
        {
            "author": "/authors/1?fields=%22%2Fcomments%2F%2A%2F%40id%22%2C+%22%2F%40id%22%2C+%22%2FfirstName%22",
            "@id": "/greetings/8",
            "name": "fdgfdg"
        },
        {
            "author": "/authors/1?fields=%22%2Fcomments%2F%2A%2F%40id%22%2C+%22%2F%40id%22%2C+%22%2FfirstName%22",
            "@id": "/greetings/9",
            "name": "CCC"
        },
        {
            "author": "/authors/1?fields=%22%2Fcomments%2F%2A%2F%40id%22%2C+%22%2F%40id%22%2C+%22%2FfirstName%22",
            "@id": "/greetings/10",
            "name": "123456"
        }
    ]
}

My author (pushed)

{
  "comments": [
    "/comments/1?fields=%22%2F%40id%22"
  ],
  "@id": "/authors/1",
  "firstName": "BenWa"
}

My comment (not push but good fields)

{
  "@id": "/comments/1"
}

Thanks for your time.

BenWa

from vulcain.

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.