Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New resolvers functions #18

Merged
merged 8 commits into from
May 26, 2019
Merged

New resolvers functions #18

merged 8 commits into from
May 26, 2019

Conversation

victufell
Copy link
Contributor

@victufell victufell commented May 25, 2019

Hello, here in this PR I add two functions that helped me a lot in my day to day, I think it would be very useful to already contain in dinoql.

getProp

With getProp we can access object properties without having to keep repeating keys, but the main advantage is being able to keep a structure in the middle of the object (something that we can do with keep: true, but only at the top of the object)

example

const newData = {
  requests: {
    users: { id: 10, name:  { text: 'Victor  Fellype' } },
      information: { 
        title: { text: 'my title' }, 
        description: { text: 'my description' } 
     }
  }
};

const data = dql(newData)`
   requests {
     users(getProp: name)
       information {
         title(getProp: text)
         description(getProp: text)
       }
  }
`

with that we can avoid thinks like:

const data = dql(newData)`
   requests {
     users {
        name {
           name: text
        }
     }
       information {
         title {
           title: text
        }
         description {
           description: text
         }
       }
  }
`

getPath

With getPath we can access very deep objects in a much more friendly way

example

const newData = {
  requests: {
      cms: {
        footer_data: {
          social_networks: [
             { name: 'facebook', url: 'facebook.com' },
             { name: 'instagram', url: 'instagram.com' }
          ]
       }
     }
  }
}

const data = dinoql(newData)`
   requests(getPath: "cms.footer_data.social_networks")
`
console.log(data)
/*
  {
     requests: [
       { name: 'facebook', url: 'facebook.com' },
       { name: 'instagram', url: 'instagram.com' }
     ]
 }
*/

with that we can avoid thinks like:

requests {
    cms  {
       footer_data {
         social_networks
       }
   }
}

Copy link
Owner

@victorvoid victorvoid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks so good man, great resolvers!

@victorvoid victorvoid merged commit 9030a3e into victorvoid:master May 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants