prisma-archive / graphcool-lib Goto Github PK
View Code? Open in Web Editor NEWA convenient tool to use in Graphcool functions to make requests against your Graphcool API
A convenient tool to use in Graphcool functions to make requests against your Graphcool API
const client = new Graphcool(projectAlias, {
pat: token,
}).api('simple/v1');
doesn't work, results in error message:
'Project not found: '''
even if <alias>
is a valid project alias.
Because subscription endpoint addresses are dynamic based on region, it would be helpful if you could expose a method to retrieve it. I will add a FR to the graphcool repo to add it to the System API, although it could also be constructed from just getting the project region from the System API.
🚨 You need to enable Continuous Integration on all branches of this repository. 🚨
To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because we are using your CI build statuses to figure out when to notify you about breaking changes.
Since we did not receive a CI status on the greenkeeper/initial
branch, we assume that you still need to configure it.
If you have already set up a CI for this repository, you might need to check your configuration. Make sure it will run on all new branches. If you don’t want it to run on every branch, you can whitelist branches starting with greenkeeper/
.
We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.
Once you have installed CI on this repository, you’ll need to re-trigger Greenkeeper’s initial Pull Request. To do this, please delete the greenkeeper/initial
branch in this repository, and then remove and re-add this repository to the Greenkeeper integration’s white list on Github. You'll find this list on your repo or organization’s settings page, under Installed GitHub Apps.
That would reduce the dependencies and footprint of graphcool-lib. See http://dev.apollodata.com/tools/graphql-tools/remote-schemas.html#fetcher-apollo-fetch for details. Using graphql-request would be exactly the same as using apollo-fetch like in the example.
The module resolution log shows is following:
======== Resolving module 'grapcool-lib' from '/Users/omatrot/Documents/some_directory/sandbox/basic ts project structure/GraphCool/queries/roomsavailability/src/hello.ts'. ========
Explicitly specified module resolution kind: 'NodeJs'.
'baseUrl' option is set to '/Users/omatrot/Documents/some_directory/sandbox/basic ts project structure/GraphCool/queries/roomsavailability', using this value to resolve non-relative module name 'grapcool-lib'.
'paths' option is specified, looking for a pattern to match module name 'grapcool-lib'.
Module name 'grapcool-lib', matched pattern ''.
Trying substitution 'node_modules/', candidate module location: 'node_modules/grapcool-lib'.
Loading module as file / folder, candidate module location '/Users/omatrot/Documents/some_directory/sandbox/basic ts project structure/GraphCool/queries/roomsavailability/node_modules/grapcool-lib', target file type 'TypeScript'.
File '/Users/omatrot/Documents/some_directory/sandbox/basic ts project structure/GraphCool/queries/roomsavailability/node_modules/grapcool-lib.ts' does not exist.
File '/Users/omatrot/Documents/some_directory/sandbox/basic ts project structure/GraphCool/queries/roomsavailability/node_modules/grapcool-lib.tsx' does not exist.
File '/Users/omatrot/Documents/some_directory/sandbox/basic ts project structure/GraphCool/queries/roomsavailability/node_modules/grapcool-lib.d.ts' does not exist.
Directory '/Users/omatrot/Documents/some_directory/sandbox/basic ts project structure/GraphCool/queries/roomsavailability/node_modules/grapcool-lib' does not exist, skipping all lookups in it.
Trying substitution 'src/types/', candidate module location: 'src/types/grapcool-lib'.
Loading module as file / folder, candidate module location '/Users/omatrot/Documents/some_directory/sandbox/basic ts project structure/GraphCool/queries/roomsavailability/src/types/grapcool-lib', target file type 'TypeScript'.
Loading module 'grapcool-lib' from 'node_modules' folder, target file type 'TypeScript'.
Directory '/Users/omatrot/Documents/some_directory/sandbox/basic ts project structure/GraphCool/queries/roomsavailability/src/node_modules' does not exist, skipping all lookups in it.
File '/Users/omatrot/Documents/some_directory/sandbox/basic ts project structure/GraphCool/queries/roomsavailability/node_modules/grapcool-lib.ts' does not exist.
File '/Users/omatrot/Documents/some_directory/sandbox/basic ts project structure/GraphCool/queries/roomsavailability/node_modules/grapcool-lib.tsx' does not exist.
File '/Users/omatrot/Documents/some_directory/sandbox/basic ts project structure/GraphCool/queries/roomsavailability/node_modules/grapcool-lib.d.ts' does not exist.
File '/Users/omatrot/Documents/some_directory/sandbox/basic ts project structure/GraphCool/queries/roomsavailability/node_modules/@types/grapcool-lib.d.ts' does not exist.
Directory '/Users/omatrot/Documents/some_directory/sandbox/basic ts project structure/GraphCool/queries/node_modules' does not exist, skipping all lookups in it.
Directory '/Users/omatrot/Documents/some_directory/sandbox/basic ts project structure/GraphCool/node_modules' does not exist, skipping all lookups in it.
Directory '/Users/omatrot/Documents/some_directory/sandbox/basic ts project structure/node_modules' does not exist, skipping all lookups in it.
Directory '/Users/omatrot/Documents/some_directory/sandbox/node_modules' does not exist, skipping all lookups in it.
Directory '/Users/omatrot/Documents/some_directory/node_modules' does not exist, skipping all lookups in it.
Directory '/Users/omatrot/Documents/node_modules' does not exist, skipping all lookups in it.
Directory '/Users/omatrot/node_modules' does not exist, skipping all lookups in it.
Directory '/Users/node_modules' does not exist, skipping all lookups in it.
Directory '/node_modules' does not exist, skipping all lookups in it.
'baseUrl' option is set to '/Users/omatrot/Documents/some_directory/sandbox/basic ts project structure/GraphCool/queries/roomsavailability', using this value to resolve non-relative module name 'grapcool-lib'.
'paths' option is specified, looking for a pattern to match module name 'grapcool-lib'.
Module name 'grapcool-lib', matched pattern ''.
Trying substitution 'node_modules/', candidate module location: 'node_modules/grapcool-lib'.
Loading module as file / folder, candidate module location '/Users/omatrot/Documents/some_directory/sandbox/basic ts project structure/GraphCool/queries/roomsavailability/node_modules/grapcool-lib', target file type 'JavaScript'.
File '/Users/omatrot/Documents/some_directory/sandbox/basic ts project structure/GraphCool/queries/roomsavailability/node_modules/grapcool-lib.js' does not exist.
File '/Users/omatrot/Documents/some_directory/sandbox/basic ts project structure/GraphCool/queries/roomsavailability/node_modules/grapcool-lib.jsx' does not exist.
Directory '/Users/omatrot/Documents/some_directory/sandbox/basic ts project structure/GraphCool/queries/roomsavailability/node_modules/grapcool-lib' does not exist, skipping all lookups in it.
Trying substitution 'src/types/', candidate module location: 'src/types/grapcool-lib'.
Loading module as file / folder, candidate module location '/Users/omatrot/Documents/some_directory/sandbox/basic ts project structure/GraphCool/queries/roomsavailability/src/types/grapcool-lib', target file type 'JavaScript'.
Loading module 'grapcool-lib' from 'node_modules' folder, target file type 'JavaScript'.
Directory '/Users/omatrot/Documents/some_directory/sandbox/basic ts project structure/GraphCool/queries/roomsavailability/src/node_modules' does not exist, skipping all lookups in it.
File '/Users/omatrot/Documents/some_directory/sandbox/basic ts project structure/GraphCool/queries/roomsavailability/node_modules/grapcool-lib.js' does not exist.
File '/Users/omatrot/Documents/some_directory/sandbox/basic ts project structure/GraphCool/queries/roomsavailability/node_modules/grapcool-lib.jsx' does not exist.
Directory '/Users/omatrot/Documents/some_directory/sandbox/basic ts project structure/GraphCool/queries/node_modules' does not exist, skipping all lookups in it.
Directory '/Users/omatrot/Documents/some_directory/sandbox/basic ts project structure/GraphCool/node_modules' does not exist, skipping all lookups in it.
Directory '/Users/omatrot/Documents/some_directory/sandbox/basic ts project structure/node_modules' does not exist, skipping all lookups in it.
Directory '/Users/omatrot/Documents/some_directory/sandbox/node_modules' does not exist, skipping all lookups in it.
Directory '/Users/omatrot/Documents/some_directory/node_modules' does not exist, skipping all lookups in it.
Directory '/Users/omatrot/Documents/node_modules' does not exist, skipping all lookups in it.
Directory '/Users/omatrot/node_modules' does not exist, skipping all lookups in it.
Directory '/Users/node_modules' does not exist, skipping all lookups in it.
Directory '/node_modules' does not exist, skipping all lookups in it.
======== Module name 'grapcool-lib' was not resolved. ========
In my opinion, either the .d.ts file is misplaced in the directory structure or the package.json is incorrect.
import { fromEvent, FunctionEvent } from "graphcool-lib"
const graphcool = fromEvent(event)
const api = graphcool.api("simple/v1")
//This one works only if I open up public permissions
const userId = await createGraphcoolUser(api, email, hash, username, image)
//This one returns error
const token = await graphcool.generateNodeToken(userId, "User")
I wrote more details here:
https://www.graph.cool/forum/t/temp-root-token-in-function-does-not-have-full-permissions/1785/2
The new 0.1.0 version assumes, that all endpoint URLs are set in the context by the Graphcool functions. This works well. However, when using graphcool-lib
outside Graphcool, to connect to your API, you will now have to specify all endpoints.
Having the possibility to do so is great for working with local etc., but it would be nice if the lib would still contain the default endpoint base urls used by 99% of the projects, otherwise upgrading will mean a lot of changes.
Not sure if this is still maintained or not, but it should probably have a license.
I have all permissions turned off, but when using fromEvent()
& .api()
my resolvers are able to circumvent such restrictions.
I need this method to reset my local graphcool dev server(docker) because gc local reset
does not work now.
See: Chatie/graphql#3
graphcool.generateAuthToken('abc', 'ThisModelTypeDoesNotExist')
returns a token instead of an error message.
It would be great to export the FunctionEvent type in the definition file.
To use it to type event
parameter.
import { FunctionEvent } from 'graphcool-lib'
export default async (event: FunctionEvent) => {
await new Promise(r => setTimeout(r, 50))
return {
data: {
message: `Hello ${event.data.name || 'World'}`
}
}
}
Hi!
Calling .generateNodeToken(nodeId, modelName, time)
always results in 1 month period, although function signature suggests it would generate a token with appropriate expiration period https://github.com/graphcool/graphcool-lib/blob/9a5432aa86be3d31c90240679ea05634ac189375/src/index.ts#L81
In order to support the new docker runtime with graphcool-lib
, we need to add endpoint information to the context.
I propose adjusting the GraphcoolContext
type to add the endpoint
object containing system
, simple
, relay
, subscriptions
:
export interface GraphcoolContext {
token: string
serviceId: string
alias: string
// new endpoints:
endpoints: {
system: string
simple: string
relay: string
subscriptions: string
}
}
As soon as we have the new URL scheme specced out, we should revisit this.
All endpoints in one subobject
Exact values for the shared cluster:
system
: https://api.graph.cool/system
simple
: https://api.graph.cool/simple/v1/cj8sxy1hu009i0103j0vujxhn
relay
: https://api.graph.cool/relay/v1/cj8sxy1hu009i0103j0vujxhn
subscriptions
: wss://subscriptions.graph.cool/v1/cj8t01lxf04ke0141a2fr124z
Exact values for the local cluster:
system
: http://localhost:60000/system
simple
: http://localhost:60000/simple/v1/cj8sxy1hu009i0103j0vujxhn
relay
: http://localhost:60000/relay/v1/cj8sxy1hu009i0103j0vujxhn
subscriptions
: ws://http://localhost:60000/subscriptions/v1/cj8t01lxf04ke0141a2fr124z
event.context
is undefined when graphcool-lib
is used in the lambda function (see this line)
I was able to find context
property in the event.body JSON.parse(event.body).context
Am I doing something wrong?
Adding variables as strings in JS template strings is error-prone because of escaping issues...can we get some true GraphQL variable support?
It seems at least node-fetch
and source-map-support
are actually unused.
The createSchema
method does not support authorization. This is essential for use in a Gateway.
The generateAuthToken
method is great for creating a token given a node id, typename and payload; the reverse method parseAuthToken
would be helpful in many use cases as well, for example to automatically connect a created post to the user that made the request.
Hi there,
I try to use graphcool-lib in the following way:
const client = Graphcool(gcProjectId, { token: gcToken })
const api = client.api('simple/v1')
api.request(` some graphql query`)
But I get following error: TypeError: Cannot set property 'endpoints' of undefined.
PS. I don't use fromEvent
function because I try to connect to my GraphCool db from Lambda function.
What am I doing wrong?
I think the fromEvent
function should be renamed to something that expresses what it does. A few suggestions:
graphcoolProjectContext
(or getGraphcoolProjectContext
)graphcoolProject
(or getGraphcoolProject
)graphcoolAPI
(or getGraphcoolAPI
)getFullEndpoint has a default endpoint, but api doesn't. Please add the default to api.
Many usecases for graphcool-lib
use the library in an Express webtask. It would be nice if the library could expose an Express middleware function (like bodyParser.json()
) to easily use it in Express. I now use this middleware function to make the api available directly from the req
object:
app.use((req, res, next) => {
if (req.body.context.graphcool) {
req.api = fromEvent(req.body).api('simple/v1')
};
next()
})
With the function exposed from graphcool-lib
, this can become:
app.use(graphcool.initApi())
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.