junglejs / junglejs

The Jamstack static site framework for Svelte
https://junglejs.org
MIT License
277 stars 4 forks source link

querying from json in dataSources does not output whole array, only first item #6

Closed alexnakagawa closed 4 years ago

alexnakagawa commented 4 years ago

Love the idea, y'all (: can't wait to see where development goes with this. I wish I had more javascript knowledge to help, but hope to be able to get to that point really soon.

I have a JSON in my dataSources within my jungle.config.js file which is defined as follows:

{
            format: "json", name: "athletes", items: [
                {
                    id: 1,
                    firstName: 'Jordan',
                    lastName: 'Clarkson',
                    sport: 'basketball',
                    currently: 'Point Guard for the Cleveland Cavaliers'
                },
                {
                    id: 2,
                    firstName: 'Shohei',
                    lastName: 'Ohtani',
                    sport: 'baseball',
                    currently: 'DH for the Los Angeles Angels'
                },
                {
                    id: 3,
                    firstName: 'Naomi',
                    lastName: 'Osaka',
                    sport: 'tennis',
                    currently: "Womens\' Singles Tennis Player"
                },
            ],
        },

I then perform a query:

const QUERY = `
        query {
            athletes {
                id
                                 firstName
                                 lastName
                                 sport
                                 currently
            }
        }
    `;

call {JSON.stringify(QUERYRES)} in a Svelte file in my components folder, which only returns the first item as follows:

{"athletes":{"id":1,"firstName":"Jordan","lastName":"Clarkson","sport":"basketball","currently":"Point Guard for the Cleveland Cavaliers","__typename":"Athletes"}}
ConProgramming commented 4 years ago

I should probably specify this in the docs somewhere, put Jungle expects the name for each dataSource to be the single of the name, as it adds a s to whatever the name is for the plural query. This could cause some weird things, like querying multiple of class would be classs... but as for your problem, changing format: "json", name: "athletes", .... to format: "json", name: "athlete", .... would fix it

alexnakagawa commented 4 years ago

That's very good to know! Thanks so much (: