Coder Social home page Coder Social logo

Comments (4)

vladar avatar vladar commented on June 12, 2024

Hey, thanks for reaching out!

The toolkit doesn't really care how you execute GraphQL queries. It just expects you to provide a function:

execute({ query, operationName, variables })

that returns a standard GraphQL response (actually a Promise for this response):

{
  data: {
    // response data
  },
  errors: []
}

You can use persisted queries or just send a full query. That is totally up to you. We do provide a default implementation of such execute function but you can easily swap it with your own.

If you want you can use Apollo links inside this function:

const { toPromise, execute as apolloExecute } = require('apollo-link');

const myApolloLink = createPersistedQueryLink({useGETForHashedQueries: true})
  .concat(createHttpLink({ uri: `https://${process.env.DATA_SOURCE_URL}/graphql`, fetch: fetch }))

async function execute({ query, operationName, variables }) {
  return toPromise(apolloExecute(myApolloLink , { query, operationName, variables }))
}

But as for me, apollo links introduce unnecessary overhead. Still, you can use them if you want.

from gatsby-graphql-toolkit.

stevector avatar stevector commented on June 12, 2024

Thanks @vladar! I see how I would set a custom execute when writing a source plugin using the toolkit. Do you expect that a site using your new gatsby-source-drupal-graphql would eventually be able to also override just the execute function from configuration?

from gatsby-graphql-toolkit.

vladar avatar vladar commented on June 12, 2024

I think yes. It makes sense to expose execute as an option. But it depends on how gatsby-source-drupal-graphql plugin will be implemented. So it's up to the plugin author to decide (I will just prepare an initial prototype for this).

from gatsby-graphql-toolkit.

stevector avatar stevector commented on June 12, 2024

sounds good! thanks @vladar.

from gatsby-graphql-toolkit.

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.