The graphQL platform that even covers the moon!
" GraphQL é uma linguagem de consulta. É considerada uma alternativa para arquiteturas REST, além de oferecer um serviço runtime para rodar comandos e consumir uma API.
Wikipédia
interface Planet {
id: string
name: string,
description: string
}
interface BaseApi<T> {
getAll: () => Promise<[T]>
getById: (id: string) => Promise<Planet>
}
class PlanetAPI implements BaseApi<Planet> {
private API_URL = "https://somekindofendpoint.com/api/";
public getAll = () => axios.get<Planet>(`${API_URL}/planets`);
public getById = (id: string) => axios.get(`${API_URL}`/planet/${id});
}
type Planet {
id: ID
name: String
description: String
}
type Query {
getPlanets: [Planet]
}
Schema
query VemPlaneta{
getPlanet(id: "someid") {
name
}
}
Response
{
"planet": {
"name": "Sanar"
}
}
Query
{
planet {
name
}
}
{
"data": {
"planet": {
"name": "some kind of planet"
}
}
}
Query
Response
mutation AddPlanet($input: AddPlanetInput!){
addPlanet(input: $input){
name
}
}
{
"data": {
"planet": {
"name": "some kind of planet"
}
}
}
Mutation
Response
subscription {
lastPlanet
}
{
"data": {
"planet": {
"name": "some kind of planet"
}
}
}
------------------------------------
{
"data": {
"planet": {
"name": "another planet after update"
}
}
}
Mutação
Resposta
"Apollo is a complete platform for implementing a graph over your data"
Bifrost GraphQL
function Planets() {
const { loading, error, data } = useQuery(GET_PLANETS);
if (error) return <Error />;
if (loading || !data) return <ActivityIndicator />;
return <PlanetList planets={data.planets} />;
}
"The InMemoryCache normalizes your data before saving it to the store by splitting the result into individual objects, creating a unique identifier for each object, and storing those objects in a flattened data structure"
{
isAdmin
}
{
isAdmin @client
}
Remote Root Query
Client Root Query
const client = new ApolloClient({
cache: new InMemoryCache(),
link: new HttpLink({ uri: 'http://localhost:4000' }),
resolvers
});
Apollo client also works as an local Apollo Server with Resolvers!!!
query currentAuthorPostCount($authorId: Int!) {
currentAuthorId @client @export(as: "authorId")
postCount(authorId: $authorId)
}
Nested as well
query currentAuthorPostCount($authorId: Int!) {
currentAuthor @client {
name
authorId @export(as: "authorId")
}
postCount(authorId: $authorId)
}
React Native App
$ apollo service:push --endpoint=http://localhost:4000
Linzera