Skip to content

Instantly share code, notes, and snippets.

View roytouw7's full-sized avatar

Roy Touw roytouw7

  • New Story
  • Netherlands
View GitHub Profile
package main
import "fmt"
func alfa(i int) (int, error) {
if i > 1 {
return i, nil
}
return 0, fmt.Errorf("i was greater than 1")
mutation {
createProduct(data:{
name: "Apple",
price: {
create: [
{
price: 1.20,
store: {
create: {
name: "Jumbo"
<div>
<div *ngFor="let product of products$ | async">
Product: {{product.name}}
<div *ngFor="let price of product.price.data">
Store: {{price?.store?.name}} Price: {{price?.price}}
</div>
</div>
</div>
<div>
<div *ngFor="let product of products$ | async">
{{product.name}}
<div *ngFor="let price of product.price.data">
{{price.price}}
</div>
</div>
</div>
import { Component, OnInit } from '@angular/core';
import { ProductService } from 'src/app/services/data/product.service';
import { Observable } from 'rxjs';
import { Products_allProducts_data } from 'src/app/services/data/__generated__/Products';
@Component({
selector: 'app-list',
templateUrl: './list.component.html',
styleUrls: ['./list.component.scss'],
})
getProducts(): Observable<(Products_allProducts_data)[]> {
return this.apollo.watchQuery<Products>({query: this.query, pollInterval: 120000}).valueChanges.pipe(
map(result => result.data.allProducts.data),
filter((x): x is Products_allProducts_data[] => x !== null)
);
}
apollo client:codegen \
--header="Authorization: Bearer REPLACE_WITH_YOUR_FAUNA_SECRET_KEY" \
--endpoint=https://graphql.fauna.com/graphql \
--target=typescript
// This file can be replaced during build by using the `fileReplacements` array.
// `ng build --prod` replaces `environment.ts` with `environment.prod.ts`.
// The list of file replacements can be found in `angular.json`.
export const environment = {
production: false,
FAUNA_KEY: 'the secret fauna key you copied earlier',
FAUNA_ENDPOINT: 'https://graphql.fauna.com/graphql',
};
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { environment } from 'src/environments/environment';
import { ApolloBoost, ApolloBoostModule } from 'apollo-angular-boost';
import { HttpClientModule } from '@angular/common/http';
@NgModule({
declarations: [],
imports: [CommonModule],
exports: [HttpClientModule, ApolloBoostModule],
@roytouw7
roytouw7 / schema.gql
Created December 10, 2020 15:36
The sample database schema.
type Product {
name: String!
price: [Price!]! @relation
}
type Store {
name: String!
price: Price
}