![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
A simple and pythonic way to query GraphQL endpoints without having to do any string manipulation.
A simple and pythonic way to query GraphQL endpoints without having to do any string manipulation.
Grafliq is a GraphQL client that provides a convenient way to handle GraphQL queries. Instead of building your query by manipulating and concatenating strings, you build your queries using function calls, eliminating all the complications and problems associated with string manipulation, and making maintenance an easy task.
Grafliq only supports the query
operation of GraphQL, there is no support
for mutations
and subscriptions
and there will be none in the foreseeable future.
Install using pip:
pip install grafliq
Let's say we want to have a GraphQL query with the following structure:
{
category(name: "household-appliances") {
electronics {
gaming_consoles(
fromReleaseDate: "2000-01-01"
fromPrice: "150"
discontinued: false
colors: [BLACK, WHITE, RED]
) {
brand
name
color
discontinued
release_date
price(currency: "euro")
model {
name
version
}
customer_rating(fromRatingDate: "2002-10-01") {
count
rates {
average(decimalCount: 2)
highest
lowest
}
}
}
}
}
}
We can generate the above query using the following Python code:
from datetime import date
from grafliq.builder import GraphQL
from grafliq.query import NestedField, Quote, NoQuote, CustomizableField
query = GraphQL(
endpoint='http://127.0.0.1:8080/graphql-api'
).category(
name='household-appliances'
).electronics(
).gaming_consoles(
'brand', 'name', 'color', 'discontinued', 'release_date',
CustomizableField('price', currency="euro"),
NestedField('model',
'name', 'version'),
NestedField('customer_rating',
'count',
NestedField('rates',
CustomizableField('average', decimalCount=2),
'highest', 'lowest'),
fromRatingDate=date(2002, 10, 1)),
fromReleaseDate=date(2000, 1, 1),
fromPrice=Quote(150),
discontinued=False,
colors=NoQuote(['BLACK', 'WHITE', 'RED'])
)
"""
To get the query as a string, you can either do this:
"""
query_string1 = str(query)
"""
Or you can call `.generate()` on the query object:
"""
query_string2 = query.generate()
"""
If you pass the `endpoint` to the `GraphQL` initializer, you can
call `.execute()` directly on the query object to call the remote API and get the result:
"""
result = query.execute()
"""
Note that if you have not passed the `endpoint` to the
`GraphQL` initializer, by calling the `.execute()` function, an error will be raised.
"""
As shown in the example above, any operation available in the remote GraphQL API
will be available as a function on the GraphQL
object.
If you want to dynamically generate GraphQL queries (.ex in an automated script, from user input, ...), you can do this with the following example, which will generate exactly the same GraphQL query:
from datetime import date
from grafliq.builder import GraphQL
from grafliq.query import NestedField, Quote, NoQuote, CustomizableField
query = GraphQL(
endpoint='http://127.0.0.1:8080/graphql-api'
).query(
'category',
name='household-appliances'
).query(
'electronics'
).query(
'gaming_consoles',
'brand', 'name', 'color', 'discontinued', 'release_date',
CustomizableField('price', currency="euro"),
NestedField('model',
'name', 'version'),
NestedField('customer_rating',
'count',
NestedField('rates',
CustomizableField('average', decimalCount=2),
'highest', 'lowest'),
fromRatingDate=date(2002, 10, 1)),
fromReleaseDate=date(2000, 1, 1),
fromPrice=Quote(150),
discontinued=False,
colors=NoQuote(['BLACK', 'WHITE', 'RED'])
)
I appreciate any kind of contribution to the development of Grafliq, especially to add support for mutations and subscriptions.
FAQs
A simple and pythonic way to query GraphQL endpoints without having to do any string manipulation.
We found that grafliq demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.