How do I parse string FQL to a query using faunadb-js? - faunadb

Let's say I have a string like const fql = "CreateCollection({ name: "users" })". How do I turn it into a faunadb Expr in JS?

You landed on the correct answer yourself. FQL is not a string-based language. This approach avoids problems like SQL injection, but it does mean you need to compose queries somewhere using a driver, the console, or a tool like Fauna Schema Migrate (FSM).
const fql = "CreateCollection({ name: "users" })"
The example you give leans toward schema/resource management. If that's your actual need here, consider FSM or the Fauna Serverless Framework plugin.
If you're building a front-end app using JavaScript, FSM is probably the right approach as it drops right into your app. It might also give you some more hints at how to transform strings into FQL. You would do the above in a single FQL file, e.g., fauna/resources/collections/users.fql as:
CreateCollection({ name: "users" })
If you're doing infrastructure as code in a separate pipeline or are already building with the Serverless Framework, the plugin might be a better fit.
If you want to see something else like a Pulumi or Terraform provider plugins, please submit a feature request in the forums!

The only way to do this at the moment seems to be evaluating the FQL as JavaScript.
The fauna-shell eval command is implemented using esprima to parse the FQL as ECMAScript, then running it through node's vm api with escodegen.
It's likely easier to just rewrite FQL files as JS files if you have the option!

Related

Accessing GraphiQL over a JWT protected route in ExpressJS

So far I've always had one big painpoint with GraphQL.
I'm very well aware that you can specify headerEditorEnabled when you setup express-graphql like this:
graphiql: { headerEditorEnabled: true, },
However, that doesn't really help if you've protected the /graphql route to begin with.
As far as I'm aware, you'll need to validate the access token before you define the context, to be able to put the user (if successful) inside the context so it is easily available in the resolvers.
I only found 1 resource adressing this issue: https://medium.com/codelit/accessing-graphiql-over-a-jwt-protected-route-in-expressjs-b2f4de6c7dd8 and I don't particularly like the solution of installing the modheader chrome extension, as it will messup other websites if you forget to enable it. Also it seems like a hacky workaround.
So I'm curious what other alternatives there might be to get graphiql working in such a scenario. So far I'm just using postman, which is equally as good for specifying the query, however it does lack the ability to browse through the schema, so getting graphiql to work would be best, if possible :-)

karate api test: how to store all responses of a feature file in an array [duplicate]

Using Karate i am making API calls sequentially. I need to store API request and response for this sequential flow of APIs in separate text files for each API call.
Need to understand how can i achieve this.
I have tried logback which stores entire execution logs in a text file.
Take a look at karate.prevRequest which will give you the "request". Now use some custom Java (or JS) code and write whatever you want to a file.
I think personally it is un-necessary because Karate's HTML report has all that you need. If someone is asking you to do this, please try convince that person that this exercise is a waste of time.

Backend database used in the API

By going through this API documentation page, is it possible to tell which database is being used in the backend?
Zomato API
MySQL would require a php file on the server to handle the requests, make queries, pack data in JSON format then send it back to the device. But in this case parameters are passed to .json files. Please advice
There is no way to "see through" to what the backend service actually used to provide you with the information you may query for. Are you sure you want to continue using this product? The site notes that Zomato will no longer be available to individuals, and that your API key will be disabled if you don't use it monthly.
I haven't read the specs for that particular API. But in general, is it possible to tell what database is being used on the back end by studying an API? No. That's the whole point of an API: It's supposed to shield the API-user from implementation details.
It's probably true that in many cases you could make reasonable guesses about what tools are being used on the back end. Like if you see that the API gives you a syntax for doing comparisons that looks exactly like the proprietary compare function used in Foobar SQL and not found in any other database product, that would be a strong clue. But even something like that wouldn't be proof. Maybe originally they were using Foobar SQL, then they switched to another database, but to maintain compatibility they wrote code to translate the Foobar SQL compare to standard SQL syntax.

create query using webservice api for Rally

I am trying to write a query in Ruby to insert a user story in Rally using WSAPI. I read through https://rally1.rallydev.com/slm/doc/webservice/.I looked it up and found that wsapi has a create() method, but I am not aware of its signature. I know it uses PUT/Post method for creation, but I just need an example to understand how to write create queries. Does anyone know of any useful resource to know more about this? I have all my code ready, just need information about writing "create" queries using Rally's WSAPI.
Thanks
There is a full directory of Ruby REST examples in the Github Repository for RallyRestToolkitForRuby:
https://github.com/RallyTools/RallyRestToolkitForRuby/tree/master/examples
This create example may be of particular interest. It's for a Defect, but the same logic would apply to Stories:
04-create-defect.rb

Meteor: Integration with Mongoose?

I noticed you guys are planning on adding more ORM features into your platform, but in the meantime, is there an easy way to extend your Collections with Mongoose Collections?
You should be able to add:
npm install mongoose
To "admin/generate-dev-bundle.sh"
You can then create a new package and require mongoose, within that you can assign the method to: Meteor.mongoose too and connect to the MONGO_URL (This is Meteors database) for this command. Take a look round the other packages if you need some help.
I did the sample work in this branch:
https://github.com/jonathanKingston/meteor/tree/mongoose
This is 100% untested as I'm on a windows machine at the moment but it should open up:
Meteor.mongoose and just normal mongoose for the standard use as explained here but already connected:
https://github.com/LearnBoost/mongoose#readme
an issue with mongoose is that it won't work on the client. So you'll lose much of the benefit of using Meteor.
Take a look at Collections2 it offers validation and structure.
Good luck!