const debug = require('debug')('apollo-local')

/**
* Create a local graphql networkInterface for apollo-client.
*
* See:
* https://github.com/apollostack/apollo-client/issues/962
* https://github.com/apollostack/apollo-client/blob/master/src/transport/networkInterface.ts
*
* @arg {Object} graphql - The graphql-js library. ie, the result of require('graphql')
* @arg {GraphQLSchema} schema - The schema you create for your GraphQL API.
*                               See http://graphql.org/graphql-js/type/#graphqlschema
* @arg {Object} options=
*   @arg {Object} options.rootValue - The optional root value argument for graphqljs
*   @arg {Object} options.context - Optional context for the graphql query
* @return {Promise<GraphQLResult>} - The result of the GraphQL query
*/
const createLocalInterface = (graphql, schema, {rootValue = null, context = null} = {}) => {
    const {execute} = graphql

    return {
        query: ({query, variables, operationName, debugName}) => {
            const start = new Date()
            var result

            try {
                result = execute(schema, query, rootValue, context, variables, operationName)
            } catch (err) {
                return Promise.reject(err)
            }

            return result.then(data => {
                debug(`${operationName} (${(new Date() - start)}ms)`)
                return data
            })
        }
    }
}

module.exports = {createLocalInterface}


@@ -1031,19 +1031,187 @@
     
-var result%0A
+let result%0A%0A            // execute() can throw if its arguments aren't valid, so we need to wrap with try/catch%0A            // See http://graphql.org/graphql-js/execution/#execute
 %0A   
@@ -1347,16 +1347,93 @@
 (err) %7B%0A
+                debug(%60$%7BoperationName%7D failed to execute ($%7Berr.message%7D)%60)%0A
         

Add explanatory comment for execute() and log execution failures